// Rust 1.89.0 flags `StorageType` as unused even with `bigtable` set as a default feature.
#[allow(dead_code)]
#[derive(Clone, Eq, PartialEq, Debug)]
pub(crate) enum StorageType {
    #[cfg(feature = "bigtable")]
    BigTable,
    #[cfg(feature = "postgres")]
    Postgres,
    #[cfg(feature = "redis")]
    Redis,
    None,
}

impl Default for StorageType {
    // It's OK clippy, we're setting a default.
    #[allow(unreachable_code)]
    fn default() -> StorageType {
        #[cfg(feature = "bigtable")]
        return StorageType::BigTable;
        #[cfg(feature = "redis")]
        return StorageType::Redis;
        #[cfg(feature = "postgres")]
        return StorageType::Postgres;
        #[cfg(not(any(feature = "bigtable", feature = "redis", feature = "postgres")))]
        return StorageType::None;
    }
}

impl From<&str> for StorageType {
    fn from(str: &str) -> StorageType {
        match str.to_lowercase().as_str() {
            #[cfg(feature = "bigtable")]
            "bigtable" => StorageType::BigTable,
            #[cfg(feature = "postgres")]
            "postgres" => StorageType::Postgres,
            #[cfg(feature = "redis")]
            "redis" => StorageType::Redis,
            _ => {
                warn!("Using default StorageType for {str}");
                StorageType::default()
            }
        }
    }
}
