pub mod rest;
pub mod pg;

use log::{info, warn};

use clap::Parser;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
    /// Generate openapi spec file with the given path and filename
    #[arg(long, short)]
    openapi: Option<String>,
}

#[tokio::main]
async fn main() {
    simple_logger::init().unwrap();
    dotenv::dotenv().ok();

    let args = Args::parse();
    if let Some(path) = args.openapi {
        let _ = rest::generate_openapi_spec::<rest::ApiDoc>(&path);
        return;
    }

    info!("Starting server...");
    let _ = tokio::spawn(async {
        let _ = rest::rest_server().await;
    }).await;

    // handle.abort();

    warn!("Server stopped");
}
