use serde::{Deserialize, Serialize};
use crate::enums::{ConcessionFeeCustomerGroup, ConcessionFeeType, Currency, Unit};
use crate::traits::{Bo4eMeta, Bo4eObject};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "json-schema", schemars(rename = "Konzessionsabgabe"))]
#[serde(rename_all = "camelCase")]
pub struct ConcessionFee {
#[serde(flatten)]
pub meta: Bo4eMeta,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "json-schema", schemars(rename = "konzessionsabgabentyp"))]
pub fee_type: Option<ConcessionFeeType>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "json-schema", schemars(rename = "kundengruppeKA"))]
pub customer_group: Option<ConcessionFeeCustomerGroup>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "json-schema", schemars(rename = "wert"))]
pub value: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "json-schema", schemars(rename = "waehrung"))]
pub currency: Option<Currency>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "json-schema", schemars(rename = "bezugseinheit"))]
pub reference_unit: Option<Unit>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "json-schema", schemars(rename = "beschreibung"))]
pub description: Option<String>,
}
impl Bo4eObject for ConcessionFee {
fn type_name_german() -> &'static str {
"Konzessionsabgabe"
}
fn type_name_english() -> &'static str {
"ConcessionFee"
}
fn meta(&self) -> &Bo4eMeta {
&self.meta
}
fn meta_mut(&mut self) -> &mut Bo4eMeta {
&mut self.meta
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_household_concession_fee() {
let fee = ConcessionFee {
fee_type: Some(ConcessionFeeType::TariffCustomer),
customer_group: Some(ConcessionFeeCustomerGroup::ElectricityTariff25000),
value: Some(1.59),
currency: Some(Currency::Eur),
reference_unit: Some(Unit::KilowattHour),
..Default::default()
};
assert_eq!(fee.fee_type, Some(ConcessionFeeType::TariffCustomer));
assert_eq!(fee.value, Some(1.59));
}
#[test]
fn test_business_concession_fee() {
let fee = ConcessionFee {
fee_type: Some(ConcessionFeeType::SpecialContractCustomer),
customer_group: Some(ConcessionFeeCustomerGroup::ElectricitySpecialCustomer),
value: Some(0.11),
currency: Some(Currency::Eur),
reference_unit: Some(Unit::KilowattHour),
..Default::default()
};
assert_eq!(
fee.customer_group,
Some(ConcessionFeeCustomerGroup::ElectricitySpecialCustomer)
);
}
#[test]
fn test_default() {
let fee = ConcessionFee::default();
assert!(fee.fee_type.is_none());
assert!(fee.value.is_none());
}
#[test]
fn test_roundtrip() {
let fee = ConcessionFee {
fee_type: Some(ConcessionFeeType::TariffCustomer),
customer_group: Some(ConcessionFeeCustomerGroup::ElectricityTariff25000),
value: Some(1.59),
description: Some("Konzessionsabgabe Strom".to_string()),
..Default::default()
};
let json = serde_json::to_string(&fee).unwrap();
let parsed: ConcessionFee = serde_json::from_str(&json).unwrap();
assert_eq!(fee, parsed);
}
#[test]
fn test_bo4e_object_impl() {
assert_eq!(ConcessionFee::type_name_german(), "Konzessionsabgabe");
assert_eq!(ConcessionFee::type_name_english(), "ConcessionFee");
}
}