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