//! DTOs for gold standard operations.

use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Request to create a new gold standard.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct CreateGoldStandardRequest {
    /// Hash of the verified assertion (hex-encoded, 32 bytes).
    pub assertion_hash: String,

    /// Subject entity (e.g., "Earth", "Semaglutide").
    pub subject: String,

    /// Predicate/relation (e.g., "has_shape", "treats_condition").
    pub predicate: String,

    /// The canonical "correct" answer for this subject-predicate pair.
    pub expected_object: String,

    /// Administrator identifier who is creating this gold standard.
    pub created_by: String,
}

/// Response from creating a gold standard.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct CreateGoldStandardResponse {
    /// Subject entity.
    pub subject: String,

    /// Predicate.
    pub predicate: String,

    /// Status message.
    pub status: String,
}

/// Gold standard data transfer object.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct GoldStandardDto {
    /// Hash of the verified assertion (hex-encoded, 32 bytes).
    pub assertion_hash: String,

    /// Subject entity.
    pub subject: String,

    /// Predicate.
    pub predicate: String,

    /// The canonical "correct" answer.
    pub expected_object: String,

    /// Unix timestamp when created (seconds).
    pub created_at: u64,

    /// Administrator who created this gold standard.
    pub created_by: String,
}

impl From<stemedb_core::types::GoldStandard> for GoldStandardDto {
    fn from(gs: stemedb_core::types::GoldStandard) -> Self {
        Self {
            assertion_hash: hex::encode(gs.assertion_hash),
            subject: gs.subject,
            predicate: gs.predicate,
            expected_object: gs.expected_object,
            created_at: gs.created_at,
            created_by: gs.created_by,
        }
    }
}

/// Response from listing gold standards.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct GoldStandardListResponse {
    /// All gold standards, ordered by subject and predicate.
    pub gold_standards: Vec<GoldStandardDto>,

    /// Total count.
    pub count: usize,
}

/// Request to verify an agent against all gold standards.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct VerifyAgentRequest {
    /// Hex-encoded agent ID (32 bytes).
    pub agent_id: String,

    /// Subject of the gold standard to verify against.
    pub subject: String,

    /// Predicate of the gold standard to verify against.
    pub predicate: String,

    /// The agent's proposed answer.
    pub agent_object: String,
}

/// Result of verifying an agent against a gold standard.
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct VerificationResult {
    /// Subject entity.
    pub subject: String,

    /// Predicate.
    pub predicate: String,

    /// Whether the agent's answer was correct.
    pub correct: bool,

    /// The agent's answer.
    pub agent_answer: String,

    /// The expected answer.
    pub expected_answer: String,

    /// The trust adjustment that was applied.
    pub trust_adjustment: f32,

    /// The agent's new trust score.
    pub new_trust_score: f32,
}
