Skip to main content

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#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
12#[cfg_attr(feature = "json-schema", schemars(rename = "Tarifkalkulationsmethode"))]
13#[non_exhaustive]
14pub enum TariffCalculationMethod {
15    /// No calculation, just multiply quantity by price
16    #[serde(rename = "KEINE")]
17    None,
18
19    /// Tier model - total quantity assigned to one tier, price applies to entire quantity
20    #[serde(rename = "STAFFELN")]
21    Tiers,
22
23    /// Zone model - total quantity distributed across zones with respective prices
24    #[serde(rename = "ZONEN")]
25    Zones,
26
27    /// Best billing within tiers
28    #[serde(rename = "BESTABRECHNUNG_STAFFEL")]
29    BestBillingTier,
30
31    /// Package price (price for a quantity package)
32    #[serde(rename = "PAKETPREIS")]
33    PackagePrice,
34}
35
36impl TariffCalculationMethod {
37    /// Returns the German name.
38    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}