//! Request DTOs for submitting data to StemeDB API.

use serde::{Deserialize, Serialize};

use super::enums::{LifecycleDto, ObjectValueDto, SignatureDto, SourceClassDto};

/// Request to create a new assertion.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateAssertionRequest {
    /// The subject entity (e.g., "Semaglutide:Type2Diabetes")
    pub subject: String,

    /// The predicate/relation (e.g., "hba1c_change_percent")
    pub predicate: String,

    /// The object value
    pub object: ObjectValueDto,

    /// Confidence score (0.0 to 1.0)
    pub confidence: f32,

    /// Agent signatures vouching for this assertion
    pub signatures: Vec<SignatureDto>,

    /// Hash of source evidence (hex-encoded)
    pub source_hash: String,

    /// Hash of parent assertion (hex-encoded, optional for forks)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent_hash: Option<String>,

    /// Source authority tier (defaults to Expert if not specified)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_class: Option<SourceClassDto>,

    /// Lifecycle stage (defaults to Proposed if not specified)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lifecycle: Option<LifecycleDto>,

    /// Structured source metadata as a JSON string.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_metadata: Option<String>,

    /// Unix timestamp when the assertion was created.
    /// Required for v2 signatures to verify correctly.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timestamp: Option<u64>,

    /// HLC timestamp for distributed causal ordering.
    /// Required for v2 signatures to verify correctly.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hlc_timestamp: Option<HlcTimestampDto>,
}

/// HLC timestamp DTO.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HlcTimestampDto {
    /// NTP64-encoded time (u64)
    pub time_ntp64: u64,

    /// Node ID (hex-encoded, 16 bytes)
    pub node_id: String,
}
