use open_feature::EvaluationContext;
use superposition_provider::{
    data_source::http::HttpDataSource,
    local_provider::LocalResolutionProvider,
    traits::{AllFeatureProvider, FeatureExperimentMeta},
    PollingStrategy, RefreshStrategy, SuperpositionOptions,
};

#[tokio::main]
async fn main() {
    env_logger::init();

    let http_source = HttpDataSource::new(SuperpositionOptions::new(
        "http://localhost:8080".to_string(),
        "token".to_string(),
        "localorg".to_string(),
        "dev".to_string(),
    ));

    let provider = LocalResolutionProvider::new(
        Box::new(http_source),
        None,
        RefreshStrategy::Polling(PollingStrategy {
            interval: 30,
            timeout: Some(10),
        }),
    );
    provider.init(EvaluationContext::default()).await.unwrap();

    let context = EvaluationContext::default()
        .with_targeting_key("user-1234")
        .with_custom_field("dimension", "d2");

    let all_config = provider
        .resolve_all_features(context.clone())
        .await
        .unwrap();
    println!("All config: {:?}", all_config);

    let variants = provider
        .get_applicable_variants(context, None)
        .await
        .unwrap();
    println!("Variants: {:?}", variants);

    provider.close_provider().await.unwrap();
}
