//! Enum DTOs for StemeDB API types.

use serde::{Deserialize, Serialize};

/// Object value in an assertion.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", content = "value")]
pub enum ObjectValueDto {
    /// Text string value
    Text(String),
    /// Numeric value (float)
    Number(f64),
    /// Boolean value
    Boolean(bool),
    /// Reference to another entity
    Reference(String),
}

/// Lifecycle stage of an assertion.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub enum LifecycleDto {
    /// Initial proposal, idea, or RFC
    Proposed,
    /// Under active review or debate
    UnderReview,
    /// Accepted as current truth
    Approved,
    /// Was true, now superseded
    Deprecated,
    /// Considered and explicitly declined
    Rejected,
}

/// Source authority tier classification.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub enum SourceClassDto {
    /// Tier 0: Regulatory bodies (FDA, EMA, WHO)
    Regulatory,
    /// Tier 1: Clinical trials, peer-reviewed research
    Clinical,
    /// Tier 2: Observational studies, real-world evidence
    Observational,
    /// Tier 3: Expert opinions, medical guidelines
    Expert,
    /// Tier 4: Curated community knowledge
    Community,
    /// Tier 5: Individual reports, testimonials, social media
    Anecdotal,
}

/// Agent signature entry.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SignatureDto {
    /// Ed25519 public key of the agent (hex-encoded, 32 bytes)
    pub agent_id: String,
    /// Ed25519 signature (hex-encoded, 64 bytes)
    pub signature: String,
    /// Timestamp when the agent signed (Unix epoch)
    pub timestamp: u64,
    /// Signature version (1 = legacy subject:predicate, 2 = content hash)
    #[serde(default = "default_version")]
    pub version: Option<u8>,
}

fn default_version() -> Option<u8> {
    Some(1)
}

/// Resolution status indicating level of agreement.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum ResolutionStatusDto {
    /// All assertions agree on the same value
    Unanimous,
    /// Strong majority (>75% weight) agrees
    Agreed,
    /// No clear consensus; significant disagreement exists
    Contested,
}

/// Lens strategy for conflict resolution (matching API).
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub enum LensQueryDto {
    /// Latest timestamp wins
    Recency,
    /// Most common object value
    Consensus,
    /// Highest assertion confidence field wins.
    Confidence,
    /// Weighted by agent reputation (TrustRank).
    Authority,
    /// Highest vote weight from VoteStore
    VoteAwareConsensus,
    /// Weighted by TrustRank reputation.
    TrustAwareAuthority,
    /// Filters assertions from superseded epochs before applying Recency.
    EpochAware,
}

impl std::fmt::Display for LensQueryDto {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            LensQueryDto::Recency => write!(f, "Recency"),
            LensQueryDto::Consensus => write!(f, "Consensus"),
            LensQueryDto::Confidence => write!(f, "Confidence"),
            LensQueryDto::Authority => write!(f, "Authority"),
            LensQueryDto::VoteAwareConsensus => write!(f, "VoteAwareConsensus"),
            LensQueryDto::TrustAwareAuthority => write!(f, "TrustAwareAuthority"),
            LensQueryDto::EpochAware => write!(f, "EpochAware"),
        }
    }
}
