//! Arguments for `mcptest baseline`.
//!
//! The baseline subcommand owns the timing-baseline file the
//! `mcptest run --check-baseline` gate reads. v1 ships `update`,
//! which folds a saved canonical run report into the baseline so a
//! CI workflow can refresh the file in place.

use std::path::PathBuf;

use clap::{Args, Subcommand};

/// Arguments for `mcptest baseline`.
#[derive(Debug, Args)]
pub struct BaselineArgs {
    /// Which baseline operation to run.
    #[command(subcommand)]
    pub command: BaselineCommand,
}

/// Subcommands for `mcptest baseline`.
#[derive(Debug, Subcommand)]
pub enum BaselineCommand {
    /// Refresh the timing baseline file with timings from a saved
    /// canonical run report. The user runs `mcptest run --reporter
    /// json --output run.json` first; this command folds the new
    /// per-test durations into the baseline.
    Update(BaselineUpdateArgs),
}

/// Arguments for `mcptest baseline update`.
#[derive(Debug, Args, Default)]
pub struct BaselineUpdateArgs {
    /// Path to the timing baseline file the command writes to. The
    /// file is created when missing. Convention is
    /// `mcptest.timing-baseline.yml` next to the suite.
    #[arg(value_name = "BASELINE")]
    pub baseline_path: PathBuf,

    /// Path to a canonical run report (the file `mcptest run
    /// --reporter json --output <PATH>` produced). The command
    /// folds each non-skipped, non-cache-hit test row from the
    /// report into the baseline.
    #[arg(long, value_name = "PATH")]
    pub from_report: PathBuf,

    /// Maximum window size for the rolling p50 / p90 update.
    /// Defaults to 20, matching the baseline file's documented
    /// default. A test with `samples >= max_samples` keeps its
    /// recorded count and the new run replaces the oldest weight
    /// in the rolling average.
    #[arg(long, value_name = "N", default_value = "20")]
    pub samples: u32,

    /// The stdio launch command to pin for the SEC-065 binary-pinning lane.
    /// Pass the full command and args, for example `--server-command uvx
    /// mcp-server`. The first token is resolved on `PATH` and its file contents
    /// are hashed into the baseline so a later binary swap is caught. Omit to
    /// keep a timing-only baseline. Mutually exclusive with `--server-url`.
    #[arg(long, value_name = "CMD", num_args = 1.., conflicts_with = "server_url")]
    pub server_command: Vec<String>,

    /// The server endpoint to pin for the SEC-065 binary-pinning lane. The host
    /// is recorded so a redirect to a different origin is caught. Mutually
    /// exclusive with `--server-command`.
    #[arg(long, value_name = "URL", conflicts_with = "server_command")]
    pub server_url: Option<String>,
}
