use serde::{Deserialize, Serialize};
use crate::entity::EntityId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum CallDirection {
Up,
Down,
}
impl CallDirection {
#[must_use]
pub fn between(origin_pos: f64, dest_pos: f64) -> Option<Self> {
if dest_pos > origin_pos {
Some(Self::Up)
} else if dest_pos < origin_pos {
Some(Self::Down)
} else {
None
}
}
#[must_use]
pub const fn opposite(self) -> Self {
match self {
Self::Up => Self::Down,
Self::Down => Self::Up,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct HallCall {
pub stop: EntityId,
pub direction: CallDirection,
pub press_tick: u64,
pub acknowledged_at: Option<u64>,
pub ack_latency_ticks: u32,
pub pending_riders: Vec<EntityId>,
pub destination: Option<EntityId>,
pub assigned_car: Option<EntityId>,
pub pinned: bool,
}
impl HallCall {
#[must_use]
pub const fn new(stop: EntityId, direction: CallDirection, press_tick: u64) -> Self {
Self {
stop,
direction,
press_tick,
acknowledged_at: None,
ack_latency_ticks: 0,
pending_riders: Vec::new(),
destination: None,
assigned_car: None,
pinned: false,
}
}
#[must_use]
pub const fn is_acknowledged(&self) -> bool {
self.acknowledged_at.is_some()
}
}