bo4e_core/enums/
tariff_feature.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 = "Tarifmerkmal"))]
13#[non_exhaustive]
14pub enum TariffFeature {
15 #[serde(rename = "STANDARD")]
17 Standard,
18
19 #[serde(rename = "VORKASSE")]
21 Prepayment,
22
23 #[serde(rename = "PAKET")]
25 Package,
26
27 #[serde(rename = "KOMBI")]
29 Combined,
30
31 #[serde(rename = "FESTPREIS")]
33 FixedPrice,
34
35 #[serde(rename = "BAUSTROM")]
37 ConstructionPower,
38
39 #[serde(rename = "HAUSLICHT")]
41 BuildingLighting,
42
43 #[serde(rename = "HEIZSTROM")]
45 HeatingPower,
46
47 #[serde(rename = "ONLINE")]
49 Online,
50}
51
52impl TariffFeature {
53 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}