use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "json-schema", schemars(rename = "Kostenklasse"))]
#[non_exhaustive]
pub enum CostClass {
#[serde(rename = "FREMDKOSTEN")]
ExternalCosts,
#[serde(rename = "BESCHAFFUNG")]
Procurement,
#[serde(rename = "SELBSTKOSTEN")]
InternalCosts,
#[serde(rename = "MARGEN")]
Margins,
#[serde(rename = "ENERGIEVERSORGUNGSKOSTEN")]
EnergySupplyCosts,
}
impl CostClass {
pub fn german_name(&self) -> &'static str {
match self {
Self::ExternalCosts => "Fremdkosten",
Self::Procurement => "Beschaffung",
Self::InternalCosts => "Selbstkosten",
Self::Margins => "Margen",
Self::EnergySupplyCosts => "Energieversorgungskosten",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize() {
assert_eq!(
serde_json::to_string(&CostClass::ExternalCosts).unwrap(),
r#""FREMDKOSTEN""#
);
assert_eq!(
serde_json::to_string(&CostClass::Procurement).unwrap(),
r#""BESCHAFFUNG""#
);
}
#[test]
fn test_roundtrip() {
for cost_class in [
CostClass::ExternalCosts,
CostClass::Procurement,
CostClass::InternalCosts,
CostClass::Margins,
CostClass::EnergySupplyCosts,
] {
let json = serde_json::to_string(&cost_class).unwrap();
let parsed: CostClass = serde_json::from_str(&json).unwrap();
assert_eq!(cost_class, parsed);
}
}
}