//! Trust graph and EigenTrust keys.

use super::builders::global_key;

/// Trust edge key: `\x00TG:{from_hex}:{to_hex}`
///
/// Stores a TrustEdge from one agent to another.
pub fn trust_edge_key(from_hex: &str, to_hex: &str) -> Vec<u8> {
    let suffix = format!("{}:{}", from_hex, to_hex);
    global_key(b"TG:", suffix.as_bytes())
}

/// Trust edge from-prefix: `\x00TG:{from_hex}:`
///
/// Scan all edges where `from_agent` is the source (outgoing edges).
pub fn trust_edge_from_prefix(from_hex: &str) -> Vec<u8> {
    let suffix = format!("{}:", from_hex);
    global_key(b"TG:", suffix.as_bytes())
}

/// Trust edge reverse key: `\x00TGR:{to_hex}:{from_hex}`
///
/// Reverse index for fast lookup of incoming edges (who trusts this agent).
pub fn trust_edge_reverse_key(to_hex: &str, from_hex: &str) -> Vec<u8> {
    let suffix = format!("{}:{}", to_hex, from_hex);
    global_key(b"TGR:", suffix.as_bytes())
}

/// Trust edge reverse prefix: `\x00TGR:{to_hex}:`
///
/// Scan all edges where `to_agent` is the target (incoming edges).
pub fn trust_edge_reverse_prefix(to_hex: &str) -> Vec<u8> {
    let suffix = format!("{}:", to_hex);
    global_key(b"TGR:", suffix.as_bytes())
}

/// Trust graph scan prefix: `\x00TG:`
///
/// Scan all trust edges in the graph.
pub fn trust_graph_scan_prefix() -> Vec<u8> {
    global_key(b"TG:", b"")
}

/// EigenTrust state key: `\x00ET:state`
///
/// Stores the computed EigenTrust state (global trust scores).
pub fn eigentrust_state_key() -> Vec<u8> {
    global_key(b"ET:state", b"")
}

/// Seed trust key: `\x00ET:seed:{agent_hex}`
///
/// Stores the seed trust value for a pre-trusted agent.
pub fn seed_trust_key(agent_hex: &str) -> Vec<u8> {
    global_key(b"ET:seed:", agent_hex.as_bytes())
}

/// Seed trust scan prefix: `\x00ET:seed:`
///
/// Scan all seed trust entries.
pub fn seed_trust_scan_prefix() -> Vec<u8> {
    global_key(b"ET:seed:", b"")
}
