Skip to main content

bo4e_core/enums/
price_model.rs

1//! Price model (Preismodell) enumeration.
2
3use serde::{Deserialize, Serialize};
4
5/// Price model for energy delivery tenders.
6///
7/// Designation of price models in tenders for energy delivery.
8///
9/// German: Preismodell
10#[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 = "Preismodell"))]
13#[non_exhaustive]
14pub enum PriceModel {
15    /// Fixed price (Festpreis)
16    #[serde(rename = "FESTPREIS")]
17    FixedPrice,
18
19    /// Tranche-based pricing (Tranche)
20    #[serde(rename = "TRANCHE")]
21    Tranche,
22}
23
24impl PriceModel {
25    /// Returns the German name.
26    pub fn german_name(&self) -> &'static str {
27        match self {
28            Self::FixedPrice => "Festpreis",
29            Self::Tranche => "Tranche",
30        }
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn test_serialize() {
40        assert_eq!(
41            serde_json::to_string(&PriceModel::FixedPrice).unwrap(),
42            r#""FESTPREIS""#
43        );
44    }
45
46    #[test]
47    fn test_roundtrip() {
48        for model in [PriceModel::FixedPrice, PriceModel::Tranche] {
49            let json = serde_json::to_string(&model).unwrap();
50            let parsed: PriceModel = serde_json::from_str(&json).unwrap();
51            assert_eq!(model, parsed);
52        }
53    }
54}