//! Core data types for StemeDB assertions and signatures.
//!
//! This module defines the fundamental data structures for the knowledge graph:
//! - **Assertions**: The atomic unit of knowledge (Subject-Predicate-Object triples)
//! - **Lifecycle**: Proposal → Review → Approved → Deprecated/Rejected
//! - **Sources**: Evidence provenance and authority tiers
//! - **Supersession**: Error correction without mutation
//! - **Voting**: High-velocity consensus without modifying assertions
//! - **Epochs**: Time-travel queries and paradigm shifts
//! - **Materialized Views**: O(1) reads for standard lenses
//! - **Query Audit**: Full provenance for "Why did you think that?" debugging
//! - **Conflict Analysis**: "Trust but Verify" for contested claims
//! - **Trust Packs**: App Store for Trust - curated agent lists
//! - **Gold Standards**: Ground truth assertions for agent verification

// Type aliases for content-addressed hashes and IDs
// -----------------------------------------------------------------------------

/// A 256-bit BLAKE3 content hash.
///
/// BLAKE3 provides cryptographic-strength collision resistance for content addressing.
/// All assertion IDs, source hashes, and epoch IDs use this representation.
///
/// # Note
/// This is a **type alias** (not a newtype), chosen for ergonomics in serialization
/// and FFI boundaries. The tradeoff is loss of compile-time type safety between
/// different hash contexts (assertion hash vs. source hash). This is accepted
/// technical debt for zero-cost abstraction at serialization boundaries.
pub type Hash = [u8; 32];

/// A 64-bit Perceptual Hash (pHash) for visual similarity detection.
///
/// Used for visual anchoring in source provenance. Two visually similar images
/// (e.g., screenshots of the same table with slight differences) will have
/// similar pHash values, enabling fuzzy matching.
///
/// # Note
/// This is a **type alias** (not a newtype). See [`Hash`] for design rationale.
pub type PHash = [u8; 8];

/// A unique identifier for an entity (Subject or Object in an assertion).
///
/// Entity IDs are human-readable strings that identify concepts, documents, or
/// real-world entities. Examples: `"Tesla_Inc"`, `"Semaglutide"`, `"PMID_38432109"`.
///
/// # Design Decision
/// This is a **type alias** for `String` (not a newtype) to avoid friction with
/// serialization, pattern matching, and string operations. The tradeoff is that
/// `EntityId` and `RelationId` are interchangeable at compile time. This is
/// accepted technical debt to preserve ergonomics and zero-copy semantics.
///
/// # Length Limits
/// See [`crate::limits::MAX_SUBJECT_LEN`] for validation constraints.
pub type EntityId = String;

/// A unique identifier for a relation (Predicate in an assertion).
///
/// Relation IDs are human-readable strings that name the relationship type.
/// Examples: `"has_revenue"`, `"treats_condition"`, `"contraindicated_with"`.
///
/// # Design Decision
/// This is a **type alias** for `String` (not a newtype). See [`EntityId`] for
/// design rationale. The lack of type distinction between EntityId and RelationId
/// is a deliberate tradeoff for serialization efficiency.
///
/// # Length Limits
/// See [`crate::limits::MAX_PREDICATE_LEN`] for validation constraints.
pub type RelationId = String;

/// A unique identifier for an Epoch (a distinct period of truth or worldview).
///
/// Epochs enable time-travel queries and paradigm shift tracking. The epoch ID
/// is the content hash of the epoch definition.
///
/// # Note
/// This is a **type alias** for `Hash` (not a newtype). See [`Hash`] for design rationale.
pub type EpochId = Hash;

/// A unique identifier for a query audit record.
///
/// Query IDs are content-addressed hashes computed from the query parameters
/// and timestamp. This enables deduplication and efficient lookup of query history.
///
/// # Note
/// This is a **type alias** for `Hash` (not a newtype). See [`Hash`] for design rationale.
pub type QueryId = Hash;

/// Content-addressed identifier for a TrustPack.
///
/// Pack IDs are BLAKE3 hashes of the pack definition, ensuring immutable identity.
/// When a pack is modified, its ID changes, enabling versioned trust lists.
///
/// # Note
/// This is a **type alias** for `Hash` (not a newtype). See [`Hash`] for design rationale.
pub type PackId = Hash;

// Sub-modules
// -----------------------------------------------------------------------------

mod analysis;
mod assertion;
mod concept;
mod content_defense;
mod epoch;
mod escalation;
mod gold_standard;
mod hlc;
mod lifecycle;
mod materialized;
mod pow;
mod query;
mod source;
mod source_record;
mod supersession;
mod trust_tier;
mod voting;

// Re-exports - Maintain backward compatibility
// -----------------------------------------------------------------------------

pub use analysis::{AgentSummary, ClaimSummary, ConflictAnalysis, ResolutionStatus, SourceSummary};
pub use assertion::{Assertion, ObjectValue, SignatureEntry};
pub use concept::{AliasOrigin, ConceptAlias, ConceptPath, ConceptPathError, SourceScheme};
pub use epoch::Epoch;
pub use escalation::{EscalationEvent, EscalationLevel, EscalationPolicy};
pub use gold_standard::GoldStandard;
pub use hlc::{bytes_to_id, detect_clock_skew, HlcTimestamp, SKEW_THRESHOLD_MS};
pub use lifecycle::LifecycleStage;
pub use materialized::{ChangeEntry, MaterializedView};
pub use query::{ContributingAssertion, QueryAudit, QueryParams};
pub use source::SourceClass;
pub use source_record::{SourceRecord, SourceStatus};
pub use supersession::{Supersession, SupersessionType};
pub use voting::{TrustPack, Vote};

// Admission control types
pub use pow::{
    AdmissionConfig, PowError, PowProof, POW_GRADUATED_THRESHOLD, POW_INITIAL_DIFFICULTY,
    POW_INITIAL_THRESHOLD, POW_MAX_AGE_SECONDS, POW_REDUCED_DIFFICULTY,
};
pub use trust_tier::{TrustTier, BASE_QUOTA_LIMIT, TRUST_POW_EXEMPTION_THRESHOLD};

// Content defense types (Phase 7C)
pub use content_defense::{ContentQuality, QuarantineDecision, QuarantineEvent, QuarantineReason};
