bo4e_core/enums/
tariff_feature.rs

1//! Tariff feature (Tarifmerkmal) enumeration.
2
3use serde::{Deserialize, Serialize};
4
5/// Tariff feature/product characteristic.
6///
7/// Product features in the context of tariff definition.
8///
9/// German: Tarifmerkmal
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[non_exhaustive]
12pub enum TariffFeature {
13    /// Standard product (Standardprodukt)
14    #[serde(rename = "STANDARD")]
15    Standard,
16
17    /// Prepayment product (Vorkassenprodukt)
18    #[serde(rename = "VORKASSE")]
19    Prepayment,
20
21    /// Package price product (Paketpreisprodukt)
22    #[serde(rename = "PAKET")]
23    Package,
24
25    /// Combined product (Kombiprodukt)
26    #[serde(rename = "KOMBI")]
27    Combined,
28
29    /// Fixed price product (Festpreisprodukt)
30    #[serde(rename = "FESTPREIS")]
31    FixedPrice,
32
33    /// Construction power product (Baustromprodukt)
34    #[serde(rename = "BAUSTROM")]
35    ConstructionPower,
36
37    /// Building lighting product (Hauslichtprodukt)
38    #[serde(rename = "HAUSLICHT")]
39    BuildingLighting,
40
41    /// Heating power product (Heizstromprodukt)
42    #[serde(rename = "HEIZSTROM")]
43    HeatingPower,
44
45    /// Online product (Onlineprodukt)
46    #[serde(rename = "ONLINE")]
47    Online,
48}
49
50impl TariffFeature {
51    /// Returns the German name.
52    pub fn german_name(&self) -> &'static str {
53        match self {
54            Self::Standard => "Standardprodukt",
55            Self::Prepayment => "Vorkassenprodukt",
56            Self::Package => "Paketpreisprodukt",
57            Self::Combined => "Kombiprodukt",
58            Self::FixedPrice => "Festpreisprodukt",
59            Self::ConstructionPower => "Baustromprodukt",
60            Self::BuildingLighting => "Hauslichtprodukt",
61            Self::HeatingPower => "Heizstromprodukt",
62            Self::Online => "Onlineprodukt",
63        }
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70
71    #[test]
72    fn test_serialize() {
73        assert_eq!(
74            serde_json::to_string(&TariffFeature::Standard).unwrap(),
75            r#""STANDARD""#
76        );
77        assert_eq!(
78            serde_json::to_string(&TariffFeature::FixedPrice).unwrap(),
79            r#""FESTPREIS""#
80        );
81    }
82
83    #[test]
84    fn test_roundtrip() {
85        for feature in [
86            TariffFeature::Standard,
87            TariffFeature::Prepayment,
88            TariffFeature::Package,
89            TariffFeature::Combined,
90            TariffFeature::FixedPrice,
91            TariffFeature::ConstructionPower,
92            TariffFeature::BuildingLighting,
93            TariffFeature::HeatingPower,
94            TariffFeature::Online,
95        ] {
96            let json = serde_json::to_string(&feature).unwrap();
97            let parsed: TariffFeature = serde_json::from_str(&json).unwrap();
98            assert_eq!(feature, parsed);
99        }
100    }
101}