//! Arguments for `mcptest judge`.

use std::path::PathBuf;

use clap::{Args, Subcommand};

/// Arguments for `mcptest judge`.
///
/// Wrapped under its own subcommand enum so further judge governance verbs can
/// land as siblings.
#[derive(Debug, Args)]
pub struct JudgeArgs {
    /// Which judge verb to run.
    #[command(subcommand)]
    pub command: JudgeCommand,
}

/// Subcommands for `mcptest judge`.
#[derive(Debug, Subcommand)]
pub enum JudgeCommand {
    /// Certify a judge/jury against a labeled anchor set before its verdict may
    /// gate CI.
    Certify(JudgeCertifyArgs),
}

/// Arguments for `mcptest judge certify`.
///
/// Reads a labeled anchor set and a rubric, computes the calibration metrics
/// (ECE, Brier, and a Rogan-Gladen corrected rate when trusted-set reliability
/// is supplied), and emits a certification record stamped with the rubric and
/// anchor-set hashes plus a validity window. Exits non-zero when any threshold
/// is missed, so CI can fail closed before a model-graded assertion gates.
#[derive(Debug, Args)]
pub struct JudgeCertifyArgs {
    /// Labeled anchor set: JSONL or a YAML array of `{confidence, correct}`
    /// rows (the same format the `calibration:` check reads).
    #[arg(long, value_name = "FILE")]
    pub labels: PathBuf,

    /// Rubric file. Its content is hashed into the record so a changed rubric
    /// invalidates the certification.
    #[arg(long, value_name = "FILE")]
    pub rubric: PathBuf,

    /// Judge model identifier recorded for provenance.
    #[arg(long, value_name = "ID")]
    pub model: Option<String>,

    /// Judge provider identifier recorded for provenance.
    #[arg(long, value_name = "NAME")]
    pub provider: Option<String>,

    /// Maximum allowed Expected Calibration Error.
    #[arg(long = "max-ece", value_name = "N", default_value = "0.10")]
    pub max_ece: f64,

    /// Maximum allowed Brier score.
    #[arg(long = "max-brier", value_name = "N", default_value = "0.25")]
    pub max_brier: f64,

    /// Minimum number of labeled verdicts the anchor set must carry.
    #[arg(long = "min-samples", value_name = "N", default_value = "10")]
    pub min_samples: usize,

    /// The judge's observed positive (pass) rate on a wider trusted set.
    /// Required together with `--reliability` to compute the corrected rate.
    #[arg(long = "observed-positive-rate", value_name = "N")]
    pub observed_positive_rate: Option<f64>,

    /// Confusion-matrix counts from a trusted set, as `tp:90,fn:10,tn:80,fp:20`.
    /// Required together with `--observed-positive-rate`.
    #[arg(long, value_name = "tp:..,fn:..,tn:..,fp:..")]
    pub reliability: Option<String>,

    /// Days the certification stays valid from issue time. Records a validity
    /// window so a stale certification can be rejected later.
    #[arg(long = "valid-days", value_name = "N", default_value = "90")]
    pub valid_days: u32,

    /// Write the certification record JSON to this path instead of stdout.
    #[arg(long, value_name = "PATH")]
    pub output: Option<PathBuf>,

    /// Overwrite the output if it already exists (off by default so a re-run
    /// cannot silently clobber a tracked or hand-edited file).
    #[arg(long)]
    pub force: bool,
}
