use crate::error::{Error, Result};
use bytes::Bytes; use std::time::SystemTime;
macro_rules! make_id {
($name:ident) => {
#[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);
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Vigil {
Sighting,
Stalking,
Offering,
Folklore,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Signet(pub String);
#[derive(Debug, Clone)]
pub struct Warren {
pub id: WarrenId,
pub owner_signet: Signet,
}
#[derive(Debug, Clone)]
pub struct FlightPlan {
pub objective_id: ObjectiveId,
pub energy_budget: u64,
pub max_duration_secs: u64,
}
#[derive(Debug, Clone)]
pub struct Sortie {
pub id: SortieId,
pub hunt_id: HuntId,
pub assigned_to: Signet,
pub task_definition: Writ,
}
#[derive(Debug, Clone)]
pub struct Writ {
pub command_id: CommandId,
pub target_subject: String,
pub payload: Bytes,
}
#[derive(Debug, Clone)]
pub struct Echo {
pub event_id: EventId,
pub topic: String,
pub payload: Bytes,
pub timestamp: SystemTime,
}
#[derive(Debug, Clone)]
pub struct Hoot {
pub source: Signet,
pub message: String,
}
#[derive(Debug, Clone)]
pub struct Shriek {
pub source: Signet,
pub disturbance: Disturbance,
}
#[derive(Debug, Clone)]
pub enum Disturbance {
FlightPlanExceeded { objective_id: ObjectiveId },
WarrenIntegrityCompromised { warren_id: WarrenId },
UnrecognizedSignet(Signet),
}