//! Arguments for `mcptest record` (WOR-1264).

use std::path::PathBuf;

use clap::Args;

/// Arguments for `mcptest record`.
///
/// Deliberately tiny: the target is where real traffic goes, the output is
/// the cassette that accumulates it, and `--front` names the transport the
/// proxy itself speaks to the client. There is no `--proxy` flag here: the
/// global `--proxy <URL>` (egress proxy) already owns that name, which is
/// recorded on the ticket.
#[derive(Debug, Args)]
pub struct RecordArgs {
    /// Real MCP server to forward to: a stdio command line (shell-quoted)
    /// or an `http(s)://` streamable-http URL.
    #[arg(long, value_name = "COMMAND|URL")]
    pub target: String,

    /// Cassette file to write. An existing cassette here is appended to
    /// across sessions, not overwritten.
    #[arg(long, value_name = "FILE", default_value = "cassettes/recorded.json")]
    pub output: PathBuf,

    /// Transport the proxy speaks to the client. Only `stdio` ships today;
    /// the HTTP front is tracked by WOR-1349.
    #[arg(long, value_name = "KIND", default_value = "stdio")]
    pub front: String,
}

#[cfg(test)]
mod tests {
    use clap::Parser;

    use crate::cli::{Cli, Command};

    #[test]
    fn record_parses_target_and_output() {
        let cli = Cli::try_parse_from([
            "mcptest",
            "record",
            "--target",
            "node server.js --port 3000",
            "--output",
            "tapes/session.json",
        ])
        .expect("parse");
        match cli.command {
            Command::Record(args) => {
                assert_eq!(args.target, "node server.js --port 3000");
                assert_eq!(args.output.display().to_string(), "tapes/session.json");
                assert_eq!(args.front, "stdio");
            }
            other => panic!("expected Record, got {other:?}"),
        }
    }

    #[test]
    fn record_requires_target() {
        let err = Cli::try_parse_from(["mcptest", "record"]).unwrap_err();
        assert!(err.to_string().contains("--target"), "{err}");
    }

    #[test]
    fn record_output_defaults_to_cassettes_recorded_json() {
        let cli = Cli::try_parse_from(["mcptest", "record", "--target", "srv"]).expect("parse");
        match cli.command {
            Command::Record(args) => {
                assert_eq!(args.output.display().to_string(), "cassettes/recorded.json");
            }
            other => panic!("expected Record, got {other:?}"),
        }
    }
}
