use sqlx::AnyPool;
use std::env;

use crate::USERS_FILESTORE;

#[derive(Clone)]
pub enum UserStore {
    File(String),
    Sql(AnyPool),
   // SqlLite(SqlitePool),
    // None
}
impl UserStore {
    #[allow(dead_code)]
    pub async fn from_str(store: &str) -> Self {
        match store {
            "fs"|"file"|"FS"|"FILE" => {
                println!("From File: {}",USERS_FILESTORE);
                UserStore::File(String::from(USERS_FILESTORE))
            }
            "db"|"DB"|_ => {
                let db_url = env::var("DATABASE_URL").unwrap_or_else(|e|{
                    eprintln!("Error env DATABASE_URL: {}",e);
                    std::process::exit(2)
                });
                let pool = AnyPool::connect(&db_url).await.unwrap_or_else(|e|{
                    eprintln!("Error pool DATABASE_URL: {}",e);
                    std::process::exit(2)
                });
                println!("From DB: {}",&db_url);
                UserStore::Sql(pool)
            },
        }
    }
}
