// server/src/main.rs
use std::env;
use dotenvy::dotenv;

// Import from the external library crate (named `server`)
use server::run_server;
use server::db;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    dotenv().ok();

    // Initialize database using library module `db`
    let db_config = db::DatabaseConfig::from_env();
    let db_pool = db::create_pool(&db_config).await?;

    match env::args().nth(1).as_deref() {
        Some("server") => run_server(db_pool).await?,
        _ => println!("Usage: cargo run -- [server|client]"),
    }

    Ok(())
}

