use serde::{Deserialize, Serialize};
use crate::entity::EntityId;
use crate::ids::GroupId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum TransportMode {
#[serde(alias = "Elevator")]
Group(GroupId),
Line(EntityId),
Walk,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RouteLeg {
pub from: EntityId,
pub to: EntityId,
pub via: TransportMode,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Route {
pub legs: Vec<RouteLeg>,
pub current_leg: usize,
}
impl Route {
#[must_use]
pub fn direct(from: EntityId, to: EntityId, group: GroupId) -> Self {
Self {
legs: vec![RouteLeg {
from,
to,
via: TransportMode::Group(group),
}],
current_leg: 0,
}
}
#[must_use]
pub fn current(&self) -> Option<&RouteLeg> {
self.legs.get(self.current_leg)
}
pub const fn advance(&mut self) -> bool {
self.current_leg += 1;
self.current_leg < self.legs.len()
}
#[must_use]
pub const fn is_complete(&self) -> bool {
self.current_leg >= self.legs.len()
}
#[must_use]
pub fn current_destination(&self) -> Option<EntityId> {
self.current().map(|leg| leg.to)
}
#[must_use]
pub fn final_destination(&self) -> Option<EntityId> {
self.legs.last().map(|leg| leg.to)
}
}