pub mod commands;
pub mod types;
pub mod utils;

use clap::{Parser, Subcommand};
use commands::js::commands::{handle_js_command, JsCommands};
use commands::completion::completion::{handle_completion_command, CompletionArgs};
use commands::image::commands::{handle_image_command, ImageCommands};
use commands::pdf::commands::{handle_pdf_command, PdfCommands};
use commands::git::commands::{handle_git_command, GitCommands};
use commands::ffmpeg::commands::{handle_ffmpeg_command, FfmpegCommands};
use types::Result;

pub mod cli {
    pub use super::{Cli, Commands};
    pub use crate::commands::js::commands::JsCommands;
    pub use crate::commands::completion::completion::CompletionArgs;
    pub use crate::commands::image::commands::ImageCommands;
    pub use crate::commands::pdf::commands::PdfCommands;
    pub use crate::commands::git::commands::GitCommands;
    pub use crate::commands::ffmpeg::commands::FfmpegCommands;
}

#[derive(Parser)]
#[command(name = "l")]
#[command(about = "A command line tool for JavaScript project management")]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
    /// JavaScript related commands
    Js {
        #[command(subcommand)]
        js_command: JsCommands,
    },
    /// Image processing commands
    Image {
        #[command(subcommand)]
        image_command: ImageCommands,
    },
    /// PDF processing commands
    Pdf {
        #[command(subcommand)]
        pdf_command: PdfCommands,
    },
    /// Git related commands
    Git {
        #[command(subcommand)]
        git_command: GitCommands,
    },
    /// FFmpeg video processing commands
    Ffmpeg {
        #[command(subcommand)]
        ffmpeg_command: FfmpegCommands,
    },
    /// Shell completion support for the CLI
    Completion(CompletionArgs),
}

pub async fn run_cli() -> Result<()> {
    let cli = Cli::parse();

    match cli.command {
        Commands::Js { js_command } => {
            handle_js_command(js_command).await
        }
        Commands::Image { image_command } => {
            handle_image_command(image_command).await
        }
        Commands::Pdf { pdf_command } => {
            handle_pdf_command(pdf_command).await
        }
        Commands::Git { git_command } => {
            handle_git_command(git_command).await
        }
        Commands::Ffmpeg { ffmpeg_command } => {
            handle_ffmpeg_command(ffmpeg_command).await
        }
        Commands::Completion(args) => {
            handle_completion_command(args.shell, args.output_dir, args.print_only).await
        }
    }
}
