//! Region metadata types.

use serde::{Deserialize, Serialize};

/// Metadata for a region (key range partition).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegionMeta {
    /// Unique region ID.
    pub id: u64,
    /// Start key (inclusive). Empty means start of keyspace.
    pub start_key: Vec<u8>,
    /// End key (exclusive). Empty means end of keyspace (infinity).
    pub end_key: Vec<u8>,
}

impl RegionMeta {
    /// Create a new region covering the entire keyspace.
    pub fn full(id: u64) -> Self {
        Self {
            id,
            start_key: Vec::new(),
            end_key: Vec::new(),
        }
    }

    /// Check if a key belongs to this region.
    pub fn contains_key(&self, key: &[u8]) -> bool {
        let start_ok = key >= self.start_key.as_slice();
        let end_ok = self.end_key.is_empty() || key < self.end_key.as_slice();
        start_ok && end_ok
    }
}
