use clap::{Parser, Subcommand};
use std::path::PathBuf;

mod generators;

#[derive(Parser)]
#[command(name = "qpq-gen", about = "Code generators for quicproquo")]
struct Cli {
    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    /// Scaffold a new server plugin (dynamic .so/.dylib)
    Plugin {
        /// Plugin name (e.g. "rate-limiter", "audit-log")
        name: String,
        /// Output directory (default: current directory)
        #[arg(short, long, default_value = ".")]
        output: PathBuf,
    },
    /// Scaffold a new bot project using the Bot SDK
    Bot {
        /// Bot name (e.g. "echo-bot", "moderation-bot")
        name: String,
        /// Output directory (default: current directory)
        #[arg(short, long, default_value = ".")]
        output: PathBuf,
    },
    /// Show instructions for adding a new Cap'n Proto RPC method
    Rpc {
        /// RPC method name in camelCase (e.g. "listChannels")
        name: String,
    },
    /// Show instructions for adding a new server hook event
    Hook {
        /// Hook event name in snake_case (e.g. "message_deleted")
        name: String,
    },
}

fn main() {
    let cli = Cli::parse();
    let result = match cli.command {
        Command::Plugin { name, output } => generators::plugin::generate(&name, &output),
        Command::Bot { name, output } => generators::bot::generate(&name, &output),
        Command::Rpc { name } => generators::rpc::generate(&name),
        Command::Hook { name } => generators::hook::generate(&name),
    };
    if let Err(e) = result {
        eprintln!("error: {e}");
        std::process::exit(1);
    }
}
