parliament 0.1.0

Protocols, traits, and domain logic for graceful governance.
Documentation
use crate::error::{Error, Result};
use bytes::Bytes; // The production-grade choice for byte buffers.
use std::time::SystemTime;

// --- Strongly-Typed Identifiers ---
macro_rules! make_id {
    ($name:ident) => {
        //  (Newtype Pattern for Correctness & Security)
        #[derive(Debug, Clone, PartialEq, Eq, Hash)]
        pub struct $name(String);

        impl $name {
            pub fn new(id: String) -> Result<Self> {
                if id.is_empty() {
                    Err(Error::InvalidIdentifier(stringify!($name).to_string()))
                } else {
                    Ok(Self(id))
                }
            }
        }

        impl AsRef<str> for $name {
            fn as_ref(&self) -> &str {
                &self.0
            }
        }

        impl From<$name> for String {
            fn from(id: $name) -> Self {
                id.0
            }
        }
    };
}

make_id!(HuntId);
make_id!(WarrenId);
make_id!(ObjectiveId);
make_id!(SortieId);
make_id!(CommandId);
make_id!(EventId);

// --- Core Lifecycle Enums ---
/// Represents the lifecycle of a major initiative, a 'Vigil'.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Vigil {
    Sighting,
    Stalking,
    Offering,
    Folklore,
}

// --- Core Data Structures ---

/// A verifiable, cryptographic identity document for a workload or user.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Signet(pub String);

/// A self-contained environment for a customer, project, or resource group.
#[derive(Debug, Clone)]
pub struct Warren {
    pub id: WarrenId,
    pub owner_signet: Signet,
}

/// A detailed plan for a 'Hunt', outlining required resources and objectives.
#[derive(Debug, Clone)]
pub struct FlightPlan {
    pub objective_id: ObjectiveId,
    pub energy_budget: u64,
    pub max_duration_secs: u64,
}

/// A single, discrete unit of work assigned to a Hunter.
#[derive(Debug, Clone)]
pub struct Sortie {
    pub id: SortieId,
    pub hunt_id: HuntId,
    pub assigned_to: Signet,
    pub task_definition: Writ,
}

// --- Messaging Primitives (Performance-Optimized) ---

/// A command payload, representing a formal directive or order to be carried out.
#[derive(Debug, Clone)]
pub struct Writ {
    pub command_id: CommandId,
    pub target_subject: String,
    pub payload: Bytes,
}

/// An event payload, representing an immutable fact that has occurred.
#[derive(Debug, Clone)]
pub struct Echo {
    pub event_id: EventId,
    pub topic: String,
    pub payload: Bytes,
    pub timestamp: SystemTime,
}

// --- Notifications ---

/// A general notification for informational purposes.
#[derive(Debug, Clone)]
pub struct Hoot {
    pub source: Signet,
    pub message: String,
}

/// An urgent warning or error notification that requires attention.
#[derive(Debug, Clone)]
pub struct Shriek {
    pub source: Signet,
    pub disturbance: Disturbance,
}

/// A structured error type for use in Shrieks.
#[derive(Debug, Clone)]
pub enum Disturbance {
    FlightPlanExceeded { objective_id: ObjectiveId },
    WarrenIntegrityCompromised { warren_id: WarrenId },
    UnrecognizedSignet(Signet),
}