//! Secondary indexes for global lookups.

use super::builders::global_key;

/// Known subjects index key: `\x00SUBJECTS:{subject}`
pub fn subjects_index_key(subject: &str) -> Vec<u8> {
    global_key(b"SUBJECTS:", subject.as_bytes())
}

/// Known subjects scan prefix: `\x00SUBJECTS:`
pub fn subjects_scan_prefix() -> Vec<u8> {
    global_key(b"SUBJECTS:", b"")
}

/// Gold standard listing index: `\x00GS_LIST:{subject}:{predicate}`
pub fn gs_list_key(subject: &str, predicate: &str) -> Vec<u8> {
    let suffix = format!("{}:{}", subject, predicate);
    global_key(b"GS_LIST:", suffix.as_bytes())
}

/// Gold standard listing scan prefix: `\x00GS_LIST:`
pub fn gs_list_scan_prefix() -> Vec<u8> {
    global_key(b"GS_LIST:", b"")
}

/// Hash-to-subject reverse index: `\x00HASH_SUBJECT:{hash_hex}`
pub fn hash_subject_key(hash_hex: &str) -> Vec<u8> {
    global_key(b"HASH_SUBJECT:", hash_hex.as_bytes())
}

/// Source-to-assertions index key: `\x00SRC:{source_hash_hex}`
///
/// Maps a source hash to a list of assertion hashes that cite it.
/// Used for cascade impact analysis when retracting sources.
pub fn source_index_key(source_hash_hex: &str) -> Vec<u8> {
    global_key(b"SRC:", source_hash_hex.as_bytes())
}

/// Source index scan prefix: `\x00SRC:`
///
/// Scan all source-to-assertions mappings.
pub fn source_index_scan_prefix() -> Vec<u8> {
    global_key(b"SRC:", b"")
}
