use saas_rs_sdk;
use std::fmt::{Debug, Display};
use std::sync::Arc;

#[allow(unused)]
macro_rules! get_config_store {
    () => {{
        const TEST_CONFIG_STORE_URL: &str = "TEST_CONFIG_STORE_URL";
        let config_store_url = match std::env::var(TEST_CONFIG_STORE_URL) {
            Ok(url) => url.parse().unwrap(),
            _ => {
                eprintln!("Skipping test because no {TEST_CONFIG_STORE_URL} is set");
                return;
            }
        };
        let belongs_tos_by_bucket = crate::testprotocol::acme::user::v1::get_belongs_tos_by_bucket();
        let has_manys_by_bucket = crate::testprotocol::acme::user::v1::get_has_manys_by_bucket();
        saas_rs_sdk::storage::config_store::adapters::new(
            &config_store_url,
            "saas-rs-sdk-tests",
            belongs_tos_by_bucket,
            has_manys_by_bucket,
        )
        .await
        .unwrap()
    }};
}

#[allow(unused)]
macro_rules! get_object_store {
    () => {{
        const TEST_OBJECT_STORE_URL: &str = "TEST_OBJECT_STORE_URL";
        let object_store_url = match std::env::var(TEST_OBJECT_STORE_URL) {
            Ok(url) => url.parse().unwrap(),
            _ => {
                eprintln!("Skipping test because no {TEST_OBJECT_STORE_URL} is set");
                return;
            }
        };
        saas_rs_sdk::storage::object_store::adapters::new(&object_store_url, "saas-rs-sdk-tests")
            .await
            .unwrap()
    }};
}

#[allow(unused)]
macro_rules! get_session_store {
    () => {{
        const TEST_SESSION_STORE_URL: &str = "TEST_SESSION_STORE_URL";
        let session_store_url = match std::env::var(TEST_SESSION_STORE_URL) {
            Ok(url) => url.parse().unwrap(),
            _ => {
                eprintln!("Skipping test because no {TEST_SESSION_STORE_URL} is set");
                return;
            }
        };
        saas_rs_sdk::storage::session_store::adapters::new(&session_store_url, "saas-rs-sdk-tests")
            .await
            .unwrap()
    }};
}

#[allow(unused)]
pub(crate) use get_config_store;

#[allow(unused)]
pub(crate) use get_object_store;

#[allow(unused)]
pub(crate) use get_session_store;
use saas_rs_sdk::storage::config_store::ConfigStore;

#[allow(unused)]
pub async fn init_config_store<B: Clone + Debug + Display + Sync + Send + 'static>(
    _store: &Arc<dyn ConfigStore<B>>,
) -> Result<(), saas_rs_sdk::storage::Error> {
    // TODO
    Ok(())
}
