//! MemTable entry type.

use stemedb_core::types::Assertion;

/// An entry in the MemTable representing an assertion waiting for KVStore indexing.
///
/// Entries are inserted after WAL commit and evicted once the IngestWorker
/// has processed them and updated the KVStore indexes.
#[derive(Debug, Clone)]
pub struct MemTableEntry {
    /// The assertion data.
    pub assertion: Assertion,
    /// The BLAKE3 hash of the serialized assertion (content-addressed ID).
    pub hash: [u8; 32],
    /// The WAL offset where this assertion was written.
    /// Used for eviction: entries with wal_offset <= indexed_offset can be evicted.
    pub wal_offset: u64,
    /// When this entry was inserted (for time-based safety eviction).
    pub inserted_at: std::time::Instant,
}

impl MemTableEntry {
    /// Create a new MemTableEntry.
    pub fn new(assertion: Assertion, hash: [u8; 32], wal_offset: u64) -> Self {
        Self { assertion, hash, wal_offset, inserted_at: std::time::Instant::now() }
    }
}
