use clap::{Parser, Subcommand};

mod client;
mod core;
mod script;
mod server;
mod ui;

#[derive(Parser)]
#[command(name = "realm", about = "A collaborative, live-service game toolkit")]
struct Cli {
    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    /// Run the game server
    Serve {
        #[arg(short = 'H', long, default_value = "0.0.0.0")]
        host: String,
        #[arg(short, long, default_value_t = 9000)]
        port: u16,
    },
    /// Run the game client
    Client {
        #[arg(short = 'H', long, default_value = "127.0.0.1")]
        host: String,
        #[arg(short, long, default_value_t = 9000)]
        port: u16,
    },
}

#[tokio::main]
async fn main() {
    let cli = Cli::parse();

    match cli.command {
        Command::Serve { host, port } => server::run(&host, port).await,
        Command::Client { host, port } => client::run(&format!("{host}:{port}")).await,
    }
}
