bo4e_core/enums/
price_status.rs

1//! Price status (Preisstatus) enumeration.
2
3use serde::{Deserialize, Serialize};
4
5/// Status information for prices.
6///
7/// German: Preisstatus
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[non_exhaustive]
10pub enum PriceStatus {
11    /// Preliminary (Vorläufig)
12    #[serde(rename = "VORLAEUFIG")]
13    Preliminary,
14
15    /// Final (Endgültig)
16    #[serde(rename = "ENDGUELTIG")]
17    Final,
18}
19
20impl PriceStatus {
21    /// Returns the German name.
22    pub fn german_name(&self) -> &'static str {
23        match self {
24            Self::Preliminary => "Vorläufig",
25            Self::Final => "Endgültig",
26        }
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn test_serialize() {
36        assert_eq!(
37            serde_json::to_string(&PriceStatus::Preliminary).unwrap(),
38            r#""VORLAEUFIG""#
39        );
40        assert_eq!(
41            serde_json::to_string(&PriceStatus::Final).unwrap(),
42            r#""ENDGUELTIG""#
43        );
44    }
45
46    #[test]
47    fn test_roundtrip() {
48        for status in [PriceStatus::Preliminary, PriceStatus::Final] {
49            let json = serde_json::to_string(&status).unwrap();
50            let parsed: PriceStatus = serde_json::from_str(&json).unwrap();
51            assert_eq!(status, parsed);
52        }
53    }
54}