use std::path::PathBuf;

use clap::{Parser, Subcommand};
use rngpui_craby_cli::commands::codegen::{perform, CodegenOptions};

#[derive(Parser)]
#[command(name = "crabygen")]
#[command(about = "Craby codegen CLI")]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Generate code from TypeScript specs
    Codegen {
        /// Project root directory
        #[arg(short, long, default_value = ".")]
        cwd: PathBuf,

        /// Overwrite existing generated files
        #[arg(short, long)]
        overwrite: bool,
    },
}

fn main() -> anyhow::Result<()> {
    env_logger::init();

    let cli = Cli::parse();

    match cli.command {
        Commands::Codegen { cwd, overwrite } => {
            let project_root = if cwd.is_absolute() {
                cwd
            } else {
                std::env::current_dir()?.join(cwd)
            };

            perform(CodegenOptions {
                project_root,
                overwrite,
            })
        }
    }
}
