bo4e_core/enums/
cost_class.rs

1//! Cost class (Kostenklasse) enumeration.
2
3use serde::{Deserialize, Serialize};
4
5/// Cost class categorization.
6///
7/// Cost classes form the top level of different costs.
8/// Typically, total costs of a cost class are calculated in an application.
9///
10/// German: Kostenklasse
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
12#[non_exhaustive]
13pub enum CostClass {
14    /// External costs (Fremdkosten)
15    #[serde(rename = "FREMDKOSTEN")]
16    ExternalCosts,
17
18    /// Procurement costs (Beschaffung)
19    #[serde(rename = "BESCHAFFUNG")]
20    Procurement,
21
22    /// Internal costs (Selbstkosten)
23    #[serde(rename = "SELBSTKOSTEN")]
24    InternalCosts,
25
26    /// Margins (Margen)
27    #[serde(rename = "MARGEN")]
28    Margins,
29
30    /// Energy supply costs (Energieversorgungskosten)
31    #[serde(rename = "ENERGIEVERSORGUNGSKOSTEN")]
32    EnergySupplyCosts,
33}
34
35impl CostClass {
36    /// Returns the German name.
37    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}