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