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