use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "json-schema", schemars(rename = "Tarifmerkmal"))]
#[non_exhaustive]
pub enum TariffFeature {
#[serde(rename = "STANDARD")]
Standard,
#[serde(rename = "VORKASSE")]
Prepayment,
#[serde(rename = "PAKET")]
Package,
#[serde(rename = "KOMBI")]
Combined,
#[serde(rename = "FESTPREIS")]
FixedPrice,
#[serde(rename = "BAUSTROM")]
ConstructionPower,
#[serde(rename = "HAUSLICHT")]
BuildingLighting,
#[serde(rename = "HEIZSTROM")]
HeatingPower,
#[serde(rename = "ONLINE")]
Online,
}
impl TariffFeature {
pub fn german_name(&self) -> &'static str {
match self {
Self::Standard => "Standardprodukt",
Self::Prepayment => "Vorkassenprodukt",
Self::Package => "Paketpreisprodukt",
Self::Combined => "Kombiprodukt",
Self::FixedPrice => "Festpreisprodukt",
Self::ConstructionPower => "Baustromprodukt",
Self::BuildingLighting => "Hauslichtprodukt",
Self::HeatingPower => "Heizstromprodukt",
Self::Online => "Onlineprodukt",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize() {
assert_eq!(
serde_json::to_string(&TariffFeature::Standard).unwrap(),
r#""STANDARD""#
);
assert_eq!(
serde_json::to_string(&TariffFeature::FixedPrice).unwrap(),
r#""FESTPREIS""#
);
}
#[test]
fn test_roundtrip() {
for feature in [
TariffFeature::Standard,
TariffFeature::Prepayment,
TariffFeature::Package,
TariffFeature::Combined,
TariffFeature::FixedPrice,
TariffFeature::ConstructionPower,
TariffFeature::BuildingLighting,
TariffFeature::HeatingPower,
TariffFeature::Online,
] {
let json = serde_json::to_string(&feature).unwrap();
let parsed: TariffFeature = serde_json::from_str(&json).unwrap();
assert_eq!(feature, parsed);
}
}
}