//! Arguments for `mcptest ledger`.
//!
//! The ledger subcommand turns a run's structured tool-call record into the
//! session-ledger artifact and gates a run against a recorded baseline, so a
//! CI workflow can fail when the agent's trajectory (which tools, in what
//! order, with what params) diverges from the expected shape.

use std::path::PathBuf;

use clap::{Args, Subcommand};

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

/// Subcommands for `mcptest ledger`.
#[derive(Debug, Subcommand)]
pub enum LedgerCommand {
    /// Diff an actual session ledger against a baseline and exit non-zero
    /// when the number of divergent tool calls exceeds `--max-diff`.
    Diff(LedgerDiffArgs),
    /// Convert a saved agent run envelope (the `tool_calls` shape mcptest
    /// produces) into a session-ledger NDJSON file.
    Emit(LedgerEmitArgs),
}

/// Arguments for `mcptest ledger diff`.
#[derive(Debug, Args)]
pub struct LedgerDiffArgs {
    /// Baseline ledger NDJSON file: the expected trajectory.
    #[arg(value_name = "BASELINE")]
    pub baseline: PathBuf,

    /// Actual ledger NDJSON file from the run under test.
    #[arg(value_name = "ACTUAL")]
    pub actual: PathBuf,

    /// Maximum number of divergent tool calls before the gate fails.
    /// Defaults to 0 (exact match required).
    #[arg(long, value_name = "N", default_value = "0")]
    pub max_diff: usize,
}

/// Arguments for `mcptest ledger emit`.
#[derive(Debug, Args)]
pub struct LedgerEmitArgs {
    /// JSON file containing an agent run envelope (with a `tool_calls` array).
    #[arg(value_name = "ENVELOPE")]
    pub input: PathBuf,

    /// Session id stamped on every record.
    #[arg(long, value_name = "ID", default_value = "session")]
    pub session_id: String,

    /// Write the ledger here 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,
}
