bo4e_core/enums/
price_model.rs1use serde::{Deserialize, Serialize};
4
5#[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 #[serde(rename = "FESTPREIS")]
17 FixedPrice,
18
19 #[serde(rename = "TRANCHE")]
21 Tranche,
22}
23
24impl PriceModel {
25 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}