use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum TariffCalculationMethod {
#[serde(rename = "KEINE")]
None,
#[serde(rename = "STAFFELN")]
Tiers,
#[serde(rename = "ZONEN")]
Zones,
#[serde(rename = "BESTABRECHNUNG_STAFFEL")]
BestBillingTier,
#[serde(rename = "PAKETPREIS")]
PackagePrice,
}
impl TariffCalculationMethod {
pub fn german_name(&self) -> &'static str {
match self {
Self::None => "Keine",
Self::Tiers => "Staffeln",
Self::Zones => "Zonen",
Self::BestBillingTier => "Bestabrechnung Staffel",
Self::PackagePrice => "Paketpreis",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize() {
assert_eq!(
serde_json::to_string(&TariffCalculationMethod::None).unwrap(),
r#""KEINE""#
);
assert_eq!(
serde_json::to_string(&TariffCalculationMethod::Tiers).unwrap(),
r#""STAFFELN""#
);
}
#[test]
fn test_roundtrip() {
for method in [
TariffCalculationMethod::None,
TariffCalculationMethod::Tiers,
TariffCalculationMethod::Zones,
TariffCalculationMethod::BestBillingTier,
TariffCalculationMethod::PackagePrice,
] {
let json = serde_json::to_string(&method).unwrap();
let parsed: TariffCalculationMethod = serde_json::from_str(&json).unwrap();
assert_eq!(method, parsed);
}
}
}