use clap::{Subcommand, Args};
use crate::types::Result;

#[derive(Args, Debug)]
pub struct RewriteIgnoreArgs {
    /// Skip confirmation
    #[arg(long, short = 'y')]
    pub yes: bool,
}

#[derive(Args, Debug)]
pub struct BakRemotesArgs {
    #[arg(long, short = 'r', help = "Remote name (default: origin)")]
    pub remote: Option<String>,

    #[arg(long, short = 'd', help = "Date string for backup prefix (default: today, e.g., 2026-04-01)")]
    pub date: Option<String>,

    #[arg(long, short = 'f', help = "Force overwrite existing backup branches", default_value_t = false)]
    pub force: bool,

    #[arg(long, short = 'u', help = "Only backup branches that have new commits since last backup", default_value_t = false)]
    pub only_updated: bool,
}

#[derive(Subcommand)]
pub enum GitCommands {
    /// Remove files from history that are currently ignored
    RewriteIgnore(RewriteIgnoreArgs),

    /// Batch backup all remote branches to local bak-{date}/{branch}
    BakRemotes(BakRemotesArgs),
}

pub async fn handle_git_command(command: GitCommands) -> Result<()> {
    match command {
        GitCommands::RewriteIgnore(args) => {
            crate::commands::git::rewrite_ignore::execute(args).await
        }
        GitCommands::BakRemotes(args) => {
            crate::commands::git::bak_remotes::execute(args).await
        }
    }
}
