use std::{error::Error, sync::OnceLock};

use common::log;
use service::GateserverService;

mod config;
mod network;
mod service;

static SERVICE: OnceLock<GateserverService> = OnceLock::new();

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    log::init_tracing();
    let config = config::load().unwrap();
    let service = GateserverService::new(config).await?;
    let service = SERVICE.get_or_init(|| service);
    service.run().await;

    Ok(())
}

fn gateserver_service() -> &'static GateserverService {
    SERVICE.get().unwrap()
}
