Skip to main content

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