bo4e_core/enums/
cost_class.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
12#[non_exhaustive]
13pub enum CostClass {
14 #[serde(rename = "FREMDKOSTEN")]
16 ExternalCosts,
17
18 #[serde(rename = "BESCHAFFUNG")]
20 Procurement,
21
22 #[serde(rename = "SELBSTKOSTEN")]
24 InternalCosts,
25
26 #[serde(rename = "MARGEN")]
28 Margins,
29
30 #[serde(rename = "ENERGIEVERSORGUNGSKOSTEN")]
32 EnergySupplyCosts,
33}
34
35impl CostClass {
36 pub fn german_name(&self) -> &'static str {
38 match self {
39 Self::ExternalCosts => "Fremdkosten",
40 Self::Procurement => "Beschaffung",
41 Self::InternalCosts => "Selbstkosten",
42 Self::Margins => "Margen",
43 Self::EnergySupplyCosts => "Energieversorgungskosten",
44 }
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_serialize() {
54 assert_eq!(
55 serde_json::to_string(&CostClass::ExternalCosts).unwrap(),
56 r#""FREMDKOSTEN""#
57 );
58 assert_eq!(
59 serde_json::to_string(&CostClass::Procurement).unwrap(),
60 r#""BESCHAFFUNG""#
61 );
62 }
63
64 #[test]
65 fn test_roundtrip() {
66 for cost_class in [
67 CostClass::ExternalCosts,
68 CostClass::Procurement,
69 CostClass::InternalCosts,
70 CostClass::Margins,
71 CostClass::EnergySupplyCosts,
72 ] {
73 let json = serde_json::to_string(&cost_class).unwrap();
74 let parsed: CostClass = serde_json::from_str(&json).unwrap();
75 assert_eq!(cost_class, parsed);
76 }
77 }
78}