use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum PriceModel {
#[serde(rename = "FESTPREIS")]
FixedPrice,
#[serde(rename = "TRANCHE")]
Tranche,
}
impl PriceModel {
pub fn german_name(&self) -> &'static str {
match self {
Self::FixedPrice => "Festpreis",
Self::Tranche => "Tranche",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize() {
assert_eq!(
serde_json::to_string(&PriceModel::FixedPrice).unwrap(),
r#""FESTPREIS""#
);
}
#[test]
fn test_roundtrip() {
for model in [PriceModel::FixedPrice, PriceModel::Tranche] {
let json = serde_json::to_string(&model).unwrap();
let parsed: PriceModel = serde_json::from_str(&json).unwrap();
assert_eq!(model, parsed);
}
}
}