use clap::Parser;
use dexter_sentinel::run_server;

#[derive(Parser, Debug)]
#[command(name = "dexter-sentinel", about = "Config-driven HTTP scrape API")]
struct Cli {
    #[arg(long, env = "HOST", default_value = "0.0.0.0")]
    host: String,

    #[arg(long, env = "PORT", default_value_t = 8080)]
    port: u16,

    #[arg(long, env = "REDIS_URL")]
    redis_url: Option<String>,

    #[arg(long, env = "ATHENA_URL")]
    athena_url: Option<String>,

    #[arg(long, env = "ATHENA_API_KEY")]
    athena_key: Option<String>,
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let cli = Cli::parse();

    std::env::set_var("HOST", &cli.host);
    std::env::set_var("PORT", cli.port.to_string());

    if let Some(url) = cli.redis_url {
        std::env::set_var("REDIS_URL", url);
    }
    if let Some(url) = cli.athena_url {
        std::env::set_var("ATHENA_URL", url);
    }
    if let Some(key) = cli.athena_key {
        std::env::set_var("ATHENA_API_KEY", key);
    }

    run_server().await
}
