use serde::{Deserialize, Serialize};
use strum::{AsRefStr, Display, EnumString};
use super::heading::Heading;
use super::travel_mode::TravelMode;
#[derive(
Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Display, EnumString, AsRefStr,
)]
pub enum SpeedUnit {
#[strum(to_string = "km/h", serialize = "kmh", serialize = "kph")]
Kmh,
#[strum(to_string = "mph")]
Mph,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct Speed {
pub value: u32,
pub unit: SpeedUnit,
}
impl Speed {
#[inline]
pub fn new(value: u32, unit: SpeedUnit) -> Self {
Self { value, unit }
}
#[inline]
pub fn in_kmh(&self) -> u32 {
match self.unit {
SpeedUnit::Kmh => self.value,
SpeedUnit::Mph => (self.value as f64 * 1.609_344).round() as u32,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct SpeedLimit {
pub max_speed: Option<Speed>,
pub min_speed: Option<Speed>,
pub heading: Option<Heading>,
pub mode: Vec<TravelMode>,
pub conditional: bool,
}