//! Central key encoding/decoding for subject-prefix range sharding.
//!
//! ALL storage keys flow through this module. Keys are partitioned into two families:
//!
//! **Subject-prefixed keys** — co-located by subject for range sharding:
//! ```text
//! {subject}\x00{TAG}:{suffix}
//! ```
//!
//! **Global keys** — metadata, trust, quotas, epochs (sort first under `\x00`):
//! ```text
//! \x00{TAG}:{suffix}
//! ```
//!
//! A prefix scan on `{subject}\x00` returns ALL data for that subject.
//! A prefix scan on `\x00` returns ALL global metadata.

/// Separator byte between subject and tag. Also serves as global key prefix.
pub const SEPARATOR: u8 = 0x00;

// ── Core modules ────────────────────────────────────────────────────

mod builders;
mod extraction;
mod validation;

// ── Key families ────────────────────────────────────────────────────

mod apikey_keys;
mod circuit_keys;
mod concept_keys;
mod defense_keys;
mod domain_keys;
mod global_keys;
mod index_keys;
mod predicate_alias_keys;
mod predicate_keys;
mod source_keys;
mod subject_keys;
mod trust_keys;
mod vector_keys;

// ── Re-exports ──────────────────────────────────────────────────────

// Validation
pub use validation::validate_subject;

// Subject-prefixed keys
pub use subject_keys::{
    assertion_key, assertion_prefix, gold_standard_key, mv_key, pack_source_key,
    pattern_aggregate_key, pattern_aggregate_scan_prefix, pattern_observation_count_key,
    pattern_project_count_key, pattern_project_set_key, pattern_project_set_scan_prefix,
    subject_index_key, subject_predicate_key, subject_predicate_scan_prefix, subject_scan_prefix,
    vote_count_key, vote_count_prefix, vote_key, vote_scan_prefix, vote_weight_key,
};

// Global keys
pub use global_keys::{
    assertion_count_key, audit_agent_index_key, audit_agent_prefix, audit_key, audit_scan_prefix,
    cursor_key, epoch_key, escalation_key, escalation_scan_prefix, gs_verified_key, quota_key,
    quota_limit_key, superseded_key, supersession_index_key, supersession_index_prefix,
    supersession_key, trust_pack_key, trust_pack_scan_prefix, trust_rank_key,
    trust_rank_scan_prefix,
};

// Index keys
pub use index_keys::{
    gs_list_key, gs_list_scan_prefix, hash_subject_key, source_index_key, source_index_scan_prefix,
    subjects_index_key, subjects_scan_prefix,
};

// Vector keys
pub use vector_keys::{vh_meta_key, vi_cold_version_key, vi_hot_cursor_key, vi_meta_key};

// Concept keys
pub use concept_keys::{alias_key, alias_reverse_key, alias_scan_prefix};

// Trust keys
pub use trust_keys::{
    eigentrust_state_key, seed_trust_key, seed_trust_scan_prefix, trust_edge_from_prefix,
    trust_edge_key, trust_edge_reverse_key, trust_edge_reverse_prefix, trust_graph_scan_prefix,
};

// Defense keys
pub use defense_keys::{
    lsh_band_scan_prefix, lsh_bucket_key, lsh_scan_prefix, minhash_key, minhash_scan_prefix,
    quarantine_hash_index_key, quarantine_key, quarantine_scan_prefix,
};

// Domain keys
pub use domain_keys::{domain_trust_agent_prefix, domain_trust_key, domain_trust_scan_prefix};

// Predicate keys
pub use predicate_keys::{
    extract_predicate_index_hash, predicate_index_key, predicate_scan_prefix,
};

// Predicate alias keys
pub use predicate_alias_keys::{predicate_alias_key, predicate_alias_scan_prefix};

// Circuit keys
pub use circuit_keys::{circuit_breaker_key, circuit_breaker_scan_prefix};

// API key keys
pub use apikey_keys::{api_key_rate_key, api_key_record_key, api_key_scan_prefix};

// Source keys
pub use source_keys::{
    extract_source_registry_label_hash, extract_source_registry_tier_hash, source_registry_key,
    source_registry_label_key, source_registry_label_prefix, source_registry_scan_prefix,
    source_registry_tier_key, source_registry_tier_prefix,
};

// Extraction utilities
pub use extraction::{
    extract_alias_path, extract_sp_key, extract_subject, extract_subject_from_subjects_key,
    extract_tag, is_global_key,
};

#[cfg(test)]
mod tests;
