bo4e_core/enums/
tariff_calculation_method.rs

1//! Tariff calculation method (Tarifkalkulationsmethode) enumeration.
2
3use serde::{Deserialize, Serialize};
4
5/// Tariff calculation method.
6///
7/// List of different calculation methods for a price sheet in tariff context.
8///
9/// German: Tarifkalkulationsmethode
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[non_exhaustive]
12pub enum TariffCalculationMethod {
13    /// No calculation, just multiply quantity by price
14    #[serde(rename = "KEINE")]
15    None,
16
17    /// Tier model - total quantity assigned to one tier, price applies to entire quantity
18    #[serde(rename = "STAFFELN")]
19    Tiers,
20
21    /// Zone model - total quantity distributed across zones with respective prices
22    #[serde(rename = "ZONEN")]
23    Zones,
24
25    /// Best billing within tiers
26    #[serde(rename = "BESTABRECHNUNG_STAFFEL")]
27    BestBillingTier,
28
29    /// Package price (price for a quantity package)
30    #[serde(rename = "PAKETPREIS")]
31    PackagePrice,
32}
33
34impl TariffCalculationMethod {
35    /// Returns the German name.
36    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}