//! Pattern CLI command definitions.

use std::path::PathBuf;

use clap::Subcommand;

#[derive(Subcommand)]
pub enum PatternCommands {
    /// Sync learned patterns to hosted server
    ///
    /// Uploads patterns that meet local thresholds (min projects, min confidence)
    /// to the hosted server for cross-project learning.
    Sync {
        /// Preview what would be synced without sending
        #[arg(long)]
        dry_run: bool,
    },

    /// Show pattern sync status
    ///
    /// Displays local pattern store stats, eligible patterns, and sync status.
    Status,

    /// Pull community extractors from hosted server
    ///
    /// Downloads extractors that have been aggregated from patterns across
    /// many organizations and saves them as YAML files.
    PullCommunity {
        /// Minimum projects threshold for community extractors (default: 50)
        #[arg(long, default_value = "50")]
        min_projects: u64,

        /// Preview without saving to disk
        #[arg(long)]
        dry_run: bool,
    },

    /// Show learned patterns with evidence information
    ///
    /// Displays patterns with their evidence levels, sources, and promotion eligibility.
    /// Evidence levels: ProductSpec > Standard > Research > Commit.
    Show {
        /// Show a specific pattern by ID (UUID format)
        #[arg(long)]
        id: Option<String>,

        /// Filter by evidence level: commit, research, standard, product_spec
        #[arg(long)]
        evidence: Option<String>,

        /// Show only patterns eligible for promotion
        #[arg(long)]
        eligible: bool,

        /// Output format: table or json
        #[arg(short, long, default_value = "table")]
        format: String,

        /// Filter by scope level: organization, team, or project
        #[arg(long)]
        scope: Option<String>,

        /// Exclude inherited patterns (show only local scope)
        #[arg(long)]
        only_local: bool,

        /// Show full inheritance chain for each pattern
        #[arg(long)]
        show_inheritance: bool,
    },
}

#[derive(Subcommand)]
pub enum EvalCommands {
    /// Run evaluation against fixtures
    Run {
        /// Path to fixtures directory
        #[arg(long, default_value = "tests/llm_fixtures")]
        fixtures: PathBuf,

        /// Categories to evaluate (comma-separated)
        #[arg(long)]
        categories: Option<String>,

        /// Maximum fixtures to run (for smoke tests)
        #[arg(long)]
        max_fixtures: Option<usize>,

        /// Evaluation mode: live, cached, mock
        #[arg(long, default_value = "mock")]
        mode: String,

        /// Exit with code 1 if regression detected
        #[arg(long)]
        fail_on_regression: bool,

        /// Regression threshold (default: 0.05 = 5%)
        #[arg(long, default_value = "0.05")]
        threshold: f64,

        /// Save observation logs
        #[arg(long)]
        save_observations: bool,

        /// Output format: table, json, markdown
        #[arg(long, default_value = "table")]
        format: String,
    },

    /// Show current baseline metrics
    Baseline {
        /// Path to fixtures directory
        #[arg(long, default_value = "tests/llm_fixtures")]
        fixtures: PathBuf,
    },

    /// Update baseline from latest run
    ///
    /// This overwrites the baseline metrics in manifest.toml.
    /// Requires --force to prevent accidental overwrites.
    UpdateBaseline {
        /// Path to fixtures directory
        #[arg(long, default_value = "tests/llm_fixtures")]
        fixtures: PathBuf,

        /// Required - prevents accidental baseline overwrites
        #[arg(long, required = true)]
        force: bool,
    },

    /// List available fixtures
    ListFixtures {
        /// Path to fixtures directory
        #[arg(long, default_value = "tests/llm_fixtures")]
        fixtures: PathBuf,

        /// Filter by category
        #[arg(long)]
        category: Option<String>,
    },

    /// Validate fixture format
    ValidateFixtures {
        /// Path to fixtures directory
        #[arg(long, default_value = "tests/llm_fixtures")]
        fixtures: PathBuf,
    },
}
