use clap::{Subcommand, Args, ValueEnum};
use std::path::PathBuf;
use crate::types::Result;

#[derive(ValueEnum, Clone, Debug)]
#[clap(rename_all = "lower")]
pub enum PaperKind {
    A4,
    Letter,
    Legal,
}

#[derive(ValueEnum, Clone, Debug)]
#[clap(rename_all = "lower")]
pub enum Orientation {
    Portrait,
    Landscape,
}

#[derive(ValueEnum, Clone, Debug)]
#[clap(rename_all = "lower")]
pub enum SortKind {
    None,
    Name,
}

#[derive(Args, Debug)]
pub struct BundleArgs {
    /// 多次传入以追加多个输入文件。支持 "path" 或 "path:angle" (如 "image.png:90")
    #[arg(short = 'i', long = "input")]
    pub inputs: Vec<String>,

    /// 目录模式：收集目录下的所有支持的文件
    #[arg(long)]
    pub dir: Option<PathBuf>,

    /// 输出文件路径（相对当前目录或绝对路径）
    #[arg(short = 'o', long = "output", default_value = "l-tool-pdf-bundle.pdf")]
    pub output: PathBuf,

    /// 纸张规格，默认 A4
    #[arg(long, value_enum, default_value_t = PaperKind::A4)]
    pub paper: PaperKind,

    /// 方向，默认竖向
    #[arg(long, value_enum, default_value_t = Orientation::Portrait)]
    pub orientation: Orientation,

    /// 排序方式，默认按名称
    #[arg(long, value_enum, default_value_t = SortKind::Name)]
    pub sort: SortKind,

    /// 全局旋转角度 (90, 180, 270)。如果输入文件指定了单独的角度 (如 path:90)，则优先使用单独角度。
    #[arg(long)]
    pub rotate: Option<i64>,
}

#[derive(Subcommand)]
pub enum PdfCommands {
    Bundle(BundleArgs),
}

pub async fn handle_pdf_command(command: PdfCommands) -> Result<()> {
    match command {
        PdfCommands::Bundle(args) => {
            crate::commands::pdf::bundle::execute(args)
        }
    }
}
