mod app;
mod input;
mod net;
mod render;
mod terminal;
mod weapon;
mod world;

use std::path::PathBuf;

use anyhow::Result;
use clap::{Parser, Subcommand};

use crate::net::protocol::DEFAULT_BIND;

#[derive(Debug, Parser)]
#[command(name = "tfps", version, about = "Terminal LAN FPS prototype")]
struct Cli {
    #[command(subcommand)]
    command: Command,
}

#[derive(Debug, Subcommand)]
enum Command {
    Server {
        #[arg(long, default_value = DEFAULT_BIND)]
        bind: String,
        #[arg(long, default_value = "maps/arena01.txt")]
        map: PathBuf,
    },
    Join {
        addr: String,
        #[arg(long, default_value = "Player")]
        name: String,
    },
}

fn main() -> Result<()> {
    let cli = Cli::parse();
    match cli.command {
        Command::Server { bind, map } => net::server::run(&bind, &map),
        Command::Join { addr, name } => app::run_client(&addr, &name),
    }
}
