//! CLI subcommands for authored claims management.

use std::path::PathBuf;

use clap::Subcommand;

/// Subcommands for managing authored claims.
#[derive(Subcommand)]
pub enum ClaimsCommands {
    /// Create a new authored claim
    Create {
        /// Human-readable claim ID (e.g., "wallet-seqcst-001")
        #[arg(long)]
        id: String,

        /// Concept path (e.g., "maxwell/wallet/atomics/ordering")
        #[arg(long)]
        concept_path: String,

        /// Predicate (e.g., "required_ordering")
        #[arg(long)]
        predicate: String,

        /// Value (parsed as bool, number, or text)
        #[arg(long)]
        value: String,

        /// Comparison mode: equals, not_equals, present, absent, contains, not_contains
        #[arg(long, default_value = "equals")]
        comparison: String,

        /// Provenance (e.g., "Safety analysis by lead developer")
        #[arg(long)]
        provenance: String,

        /// Invariant (e.g., "All wallet atomics MUST use SeqCst")
        #[arg(long)]
        invariant: String,

        /// Consequence of violation (e.g., "Double-spend race condition")
        #[arg(long)]
        consequence: String,

        /// Authority tier: regulatory, clinical, observational, expert, community, anecdotal
        #[arg(long)]
        tier: String,

        /// Supporting evidence (can be specified multiple times)
        #[arg(long)]
        evidence: Vec<String>,

        /// Category: safety, architecture, imports, constants, derives, etc.
        #[arg(long)]
        category: String,

        /// Author name
        #[arg(long)]
        by: String,
    },

    /// List authored claims
    List {
        /// Filter by category
        #[arg(long)]
        category: Option<String>,

        /// Filter by status (active, deprecated, superseded)
        #[arg(long)]
        status: Option<String>,

        /// Output format: table or json
        #[arg(long, default_value = "table")]
        format: String,
    },

    /// Generate claims-explained markdown
    Explain {
        /// Specific claim ID to explain (omit for all claims)
        #[arg(long)]
        claim: Option<String>,

        /// Output file path (default: stdout)
        #[arg(short, long)]
        output: Option<PathBuf>,

        /// Output format: markdown or json
        #[arg(long, default_value = "markdown")]
        format: String,
    },

    /// Update fields on an existing claim
    Update {
        /// Claim ID to update
        id: String,

        /// New provenance
        #[arg(long)]
        provenance: Option<String>,

        /// New invariant
        #[arg(long)]
        invariant: Option<String>,

        /// New consequence
        #[arg(long)]
        consequence: Option<String>,

        /// New authority tier
        #[arg(long)]
        tier: Option<String>,

        /// Additional evidence (appended)
        #[arg(long)]
        evidence: Vec<String>,

        /// New category
        #[arg(long)]
        category: Option<String>,

        /// New value
        #[arg(long)]
        value: Option<String>,
    },

    /// Create a new claim that supersedes an existing one
    Supersede {
        /// ID of the claim to supersede
        id: String,

        /// New claim ID
        #[arg(long)]
        new_id: Option<String>,

        /// New value
        #[arg(long)]
        value: Option<String>,

        /// New provenance
        #[arg(long)]
        provenance: Option<String>,

        /// New invariant
        #[arg(long)]
        invariant: Option<String>,

        /// New consequence
        #[arg(long)]
        consequence: Option<String>,

        /// New authority tier
        #[arg(long)]
        tier: Option<String>,

        /// New evidence
        #[arg(long)]
        evidence: Vec<String>,

        /// Author name
        #[arg(long)]
        by: Option<String>,
    },

    /// Mark a claim as deprecated
    Deprecate {
        /// Claim ID to deprecate
        id: String,

        /// Reason for deprecation
        #[arg(long)]
        reason: String,
    },

    /// Import claims from a TOML file in batch
    Import {
        /// Path to TOML file with claims (omit to generate template)
        file: Option<PathBuf>,

        /// Authority tier to apply to all claims (overrides tier in file)
        #[arg(long)]
        authority_tier: Option<String>,

        /// Source guideline name (for tracking)
        #[arg(long)]
        source_guide: Option<String>,

        /// Preview changes without writing to file
        #[arg(long)]
        dry_run: bool,

        /// Merge strategy: skip_existing, overwrite, fail_on_duplicate
        #[arg(long, default_value = "skip_existing")]
        merge: String,

        /// Generate example TOML template
        #[arg(long)]
        template: bool,

        /// Validate file without importing
        #[arg(long)]
        validate_only: bool,

        /// Output format: table or json
        #[arg(long, default_value = "table")]
        format: String,
    },

    /// List pending claim markers
    ListMarkers {
        /// Filter by status (pending, formalized, rejected)
        #[arg(long)]
        status: Option<String>,

        /// Output format: table or json
        #[arg(long, default_value = "table")]
        format: String,
    },

    /// Formalize a pending marker into a full claim
    FormalizeMarker {
        /// Marker ID to formalize
        marker_id: String,

        /// Claim ID for the new claim
        #[arg(long)]
        id: String,

        /// Authority tier (default: expert)
        #[arg(long, default_value = "expert")]
        tier: String,

        /// Supporting evidence (can be specified multiple times)
        #[arg(long)]
        evidence: Vec<String>,

        /// Author name
        #[arg(long)]
        by: String,
    },

    /// Reject a pending marker
    RejectMarker {
        /// Marker ID to reject
        marker_id: String,

        /// Reason for rejection
        #[arg(long)]
        reason: String,
    },
}
