//! Arguments for `mcptest ecosystem` (WOR-1427).

use std::path::PathBuf;

use clap::{Args, Subcommand, ValueEnum};

/// Ingest public MCP ecosystem metadata into a local corpus, or carve a
/// fixture pack out of one.
///
/// Everything is offline: the importers read files you pass in, never the
/// network, and nothing is uploaded. Cross-developer scorecards live in
/// `mcptest-enterprise`; this command is the local substrate.
#[derive(Debug, Args)]
pub struct EcosystemArgs {
    /// Which ecosystem action to run.
    #[command(subcommand)]
    pub command: EcosystemCommand,
}

/// Subcommands under `mcptest ecosystem`.
#[derive(Debug, Subcommand)]
pub enum EcosystemCommand {
    /// Normalize one or more source exports into a corpus manifest.
    Import(EcosystemImportArgs),
    /// Filter a corpus into a deterministic fixture pack.
    Select(EcosystemSelectArgs),
}

/// Arguments for `mcptest ecosystem import`.
#[derive(Debug, Args)]
pub struct EcosystemImportArgs {
    /// MCPCorpus-style JSON export to import. Repeatable.
    #[arg(long = "mcpcorpus", value_name = "PATH")]
    pub mcpcorpus: Vec<PathBuf>,

    /// Official-registry server export (JSON) to import. Repeatable.
    #[arg(long = "registry", value_name = "PATH")]
    pub registry: Vec<PathBuf>,

    /// Curated repo list (JSON array or newline-delimited URLs). Repeatable.
    #[arg(long = "repos", value_name = "PATH")]
    pub repos: Vec<PathBuf>,

    /// Write the corpus manifest here instead of stdout.
    #[arg(long, value_name = "PATH")]
    pub out: Option<PathBuf>,
}

/// Arguments for `mcptest ecosystem select`.
#[derive(Debug, Args)]
pub struct EcosystemSelectArgs {
    /// Corpus manifest to select from (the output of `ecosystem import`).
    #[arg(value_name = "CORPUS")]
    pub corpus: PathBuf,

    /// Keep only this transport.
    #[arg(long, value_enum, value_name = "TRANSPORT")]
    pub transport: Option<TransportFilter>,

    /// Keep only this implementation language (case-insensitive).
    #[arg(long, value_name = "LANG")]
    pub language: Option<String>,

    /// Keep only this role.
    #[arg(long, value_enum, value_name = "ROLE")]
    pub role: Option<RoleFilter>,

    /// Keep only entries carrying this category tag (case-insensitive).
    #[arg(long, value_name = "TAG")]
    pub category: Option<String>,

    /// Keep only entries advertising at least this many tools.
    #[arg(long, value_name = "N")]
    pub min_tools: Option<u32>,

    /// Keep only actively maintained entries.
    #[arg(long)]
    pub maintained: bool,

    /// Keep only entries usable as fixtures (a real source URL).
    #[arg(long)]
    pub fixture_ready: bool,

    /// Cap the pack at this many entries (deterministic: first N by key).
    #[arg(long, value_name = "N")]
    pub limit: Option<usize>,

    /// Write the fixture pack here instead of stdout.
    #[arg(long, value_name = "PATH")]
    pub out: Option<PathBuf>,
}

/// Transport filter values for `ecosystem select --transport`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum TransportFilter {
    /// Local stdio subprocess.
    Stdio,
    /// Streamable HTTP.
    Http,
    /// Legacy HTTP+SSE.
    Sse,
}

/// Role filter values for `ecosystem select --role`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum RoleFilter {
    /// MCP servers.
    Server,
    /// MCP clients.
    Client,
}
