use std::path::PathBuf;

use clap::{Parser, Subcommand};

#[derive(Debug, Parser)]
#[command(name = "lobe", version, about = "Lobe — local HTTP performance observer")]
pub struct Cli {
    #[arg(long, global = true)]
    pub db: Option<PathBuf>,
    #[command(subcommand)]
    pub command: Command,
}

#[derive(Debug, Subcommand)]
pub enum Command {
    Probe {
        url: String,
    },
    History {
        target: Option<String>,
        #[arg(short, long, default_value_t = 10)]
        limit: usize,
    },
    Compare {
        url: String,
        #[arg(long, default_value_t = 40.0)]
        threshold: f64,
    },
    Watch {
        url: String,
        #[arg(short, long, default_value_t = 5)]
        interval: u64,
        #[arg(long, default_value_t = 40.0)]
        threshold: f64,
        #[arg(long)]
        count: Option<usize>,
        #[arg(long)]
        tui: bool,
    },
    Capture {
        upstream: String,
        #[arg(long, default_value = "127.0.0.1:7878")]
        listen: String,
        /// Auto-upload the session to your Lobe cloud on export.
        /// Requires `lobe login` first.
        #[arg(long)]
        upload: bool,
    },
    /// Authorize this machine to sync sessions to your Lobe cloud.
    Login {
        /// Provide the token non-interactively (e.g. from CI).
        #[arg(long)]
        token: Option<String>,
        /// Override the web URL used in the auth prompt.
        /// Defaults to https://getlobe.dev.
        #[arg(long)]
        web_url: Option<String>,
        /// Override the Convex API URL used for token verification and
        /// uploads. Defaults to the shipped production URL.
        #[arg(long)]
        api_url: Option<String>,
    },
    Explain {
        /// Path to a session JSON file produced by `lobe capture` (press `e`).
        session: PathBuf,
        /// Model to use. Defaults to Haiku 4.5 for cost. Use `--model sonnet` for a deeper pass.
        #[arg(long, default_value = "haiku")]
        model: String,
        /// Write the markdown report to a file instead of stdout.
        #[arg(short, long)]
        output: Option<PathBuf>,
    },
    /// Install the lobe-diagnose skill into your AI editor of choice.
    InstallSkill {
        /// Target editor: `claude-code` or `cursor`.
        target: String,
        /// Install to your home dir (~/.claude or ~/.cursor) instead of the current project.
        #[arg(long)]
        global: bool,
        /// Overwrite an existing skill file if present.
        #[arg(long)]
        force: bool,
    },
}
