use crate::commands;
use crate::error::Result;
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(name = "lmrc")]
#[command(version, about = "LMRC Stack - Infrastructure project scaffolding tool", long_about = None)]
pub struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Create a new LMRC Stack project
    New {
        /// Optional project name (will prompt if not provided)
        name: Option<String>,

        /// Path where project will be created (defaults to current directory)
        #[arg(short, long)]
        path: Option<String>,

        /// Use configuration from file instead of interactive prompts
        #[arg(short, long)]
        config: Option<String>,
    },

    /// Generate a template configuration file
    Config {
        /// Output path for config file
        #[arg(short, long, default_value = "lmrc.toml")]
        output: String,
    },

    /// Validate an existing configuration file
    Validate {
        /// Path to configuration file
        #[arg(default_value = "lmrc.toml")]
        config: String,
    },
}

impl Cli {
    pub async fn execute(self) -> Result<()> {
        match self.command {
            Commands::New { name, path, config } => {
                commands::new::execute(name, path, config).await
            }
            Commands::Config { output } => commands::config::execute(output).await,
            Commands::Validate { config } => commands::validate::execute(config).await,
        }
    }
}
