use crate::utils::UtcTime;
use std::fmt::Display;
#[derive(Debug, Clone)]
pub struct Package {
pub barcode: String,
pub channel: String,
pub status: PackageStatus,
pub sender: Option<String>,
pub recipient: Option<String>,
pub eta: Option<UtcTime>,
pub eta_window: Option<TimeWindow>,
pub delivered: Option<UtcTime>,
pub events: Vec<Event>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimeWindow {
pub start: UtcTime,
pub end: UtcTime,
}
#[derive(Debug, Clone)]
pub struct Event {
pub timestamp: UtcTime,
pub text: String,
}
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
pub enum PackageStatus {
Delivered,
DeliveredToNeighbour { address: String },
InTransit,
}
impl PackageStatus {
pub fn is_final(&self) -> bool {
use PackageStatus::*;
match self {
Delivered => true,
DeliveredToNeighbour { address: _ } => true,
_ => false,
}
}
}
impl Display for PackageStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
#[derive(Clone)]
pub struct TrackerContext<'a> {
pub recipient_postcode: Option<&'a str>,
pub language: &'a str,
}