bo4e_core/enums/
tariff_calculation_method.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[non_exhaustive]
12pub enum TariffCalculationMethod {
13 #[serde(rename = "KEINE")]
15 None,
16
17 #[serde(rename = "STAFFELN")]
19 Tiers,
20
21 #[serde(rename = "ZONEN")]
23 Zones,
24
25 #[serde(rename = "BESTABRECHNUNG_STAFFEL")]
27 BestBillingTier,
28
29 #[serde(rename = "PAKETPREIS")]
31 PackagePrice,
32}
33
34impl TariffCalculationMethod {
35 pub fn german_name(&self) -> &'static str {
37 match self {
38 Self::None => "Keine",
39 Self::Tiers => "Staffeln",
40 Self::Zones => "Zonen",
41 Self::BestBillingTier => "Bestabrechnung Staffel",
42 Self::PackagePrice => "Paketpreis",
43 }
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_serialize() {
53 assert_eq!(
54 serde_json::to_string(&TariffCalculationMethod::None).unwrap(),
55 r#""KEINE""#
56 );
57 assert_eq!(
58 serde_json::to_string(&TariffCalculationMethod::Tiers).unwrap(),
59 r#""STAFFELN""#
60 );
61 }
62
63 #[test]
64 fn test_roundtrip() {
65 for method in [
66 TariffCalculationMethod::None,
67 TariffCalculationMethod::Tiers,
68 TariffCalculationMethod::Zones,
69 TariffCalculationMethod::BestBillingTier,
70 TariffCalculationMethod::PackagePrice,
71 ] {
72 let json = serde_json::to_string(&method).unwrap();
73 let parsed: TariffCalculationMethod = serde_json::from_str(&json).unwrap();
74 assert_eq!(method, parsed);
75 }
76 }
77}