Skip to main content

bo4e_core/com/
concession_fee.rs

1//! Concession fee (Konzessionsabgabe) component.
2
3use serde::{Deserialize, Serialize};
4
5use crate::enums::{ConcessionFeeCustomerGroup, ConcessionFeeType, Currency, Unit};
6use crate::traits::{Bo4eMeta, Bo4eObject};
7
8/// A concession fee charged by municipalities.
9///
10/// German: Konzessionsabgabe
11///
12/// # Example
13///
14/// ```rust
15/// use bo4e_core::com::ConcessionFee;
16/// use bo4e_core::enums::{ConcessionFeeType, ConcessionFeeCustomerGroup};
17///
18/// let fee = ConcessionFee {
19///     fee_type: Some(ConcessionFeeType::TariffCustomer),
20///     customer_group: Some(ConcessionFeeCustomerGroup::ElectricityTariff25000),
21///     value: Some(1.59),
22///     ..Default::default()
23/// };
24/// ```
25#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
26#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
27#[cfg_attr(feature = "json-schema", schemars(rename = "Konzessionsabgabe"))]
28#[serde(rename_all = "camelCase")]
29pub struct ConcessionFee {
30    /// BO4E metadata
31    #[serde(flatten)]
32    pub meta: Bo4eMeta,
33
34    /// Type of concession fee (Konzessionsabgabentyp)
35    #[serde(skip_serializing_if = "Option::is_none")]
36    #[cfg_attr(feature = "json-schema", schemars(rename = "konzessionsabgabentyp"))]
37    pub fee_type: Option<ConcessionFeeType>,
38
39    /// Customer group for the fee (Kundengruppe KA)
40    #[serde(skip_serializing_if = "Option::is_none")]
41    #[cfg_attr(feature = "json-schema", schemars(rename = "kundengruppeKA"))]
42    pub customer_group: Option<ConcessionFeeCustomerGroup>,
43
44    /// Fee value (Wert)
45    #[serde(skip_serializing_if = "Option::is_none")]
46    #[cfg_attr(feature = "json-schema", schemars(rename = "wert"))]
47    pub value: Option<f64>,
48
49    /// Currency (Waehrung)
50    #[serde(skip_serializing_if = "Option::is_none")]
51    #[cfg_attr(feature = "json-schema", schemars(rename = "waehrung"))]
52    pub currency: Option<Currency>,
53
54    /// Reference unit (Bezugseinheit)
55    #[serde(skip_serializing_if = "Option::is_none")]
56    #[cfg_attr(feature = "json-schema", schemars(rename = "bezugseinheit"))]
57    pub reference_unit: Option<Unit>,
58
59    /// Description (Beschreibung)
60    #[serde(skip_serializing_if = "Option::is_none")]
61    #[cfg_attr(feature = "json-schema", schemars(rename = "beschreibung"))]
62    pub description: Option<String>,
63}
64
65impl Bo4eObject for ConcessionFee {
66    fn type_name_german() -> &'static str {
67        "Konzessionsabgabe"
68    }
69
70    fn type_name_english() -> &'static str {
71        "ConcessionFee"
72    }
73
74    fn meta(&self) -> &Bo4eMeta {
75        &self.meta
76    }
77
78    fn meta_mut(&mut self) -> &mut Bo4eMeta {
79        &mut self.meta
80    }
81}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86
87    #[test]
88    fn test_household_concession_fee() {
89        let fee = ConcessionFee {
90            fee_type: Some(ConcessionFeeType::TariffCustomer),
91            customer_group: Some(ConcessionFeeCustomerGroup::ElectricityTariff25000),
92            value: Some(1.59),
93            currency: Some(Currency::Eur),
94            reference_unit: Some(Unit::KilowattHour),
95            ..Default::default()
96        };
97
98        assert_eq!(fee.fee_type, Some(ConcessionFeeType::TariffCustomer));
99        assert_eq!(fee.value, Some(1.59));
100    }
101
102    #[test]
103    fn test_business_concession_fee() {
104        let fee = ConcessionFee {
105            fee_type: Some(ConcessionFeeType::SpecialContractCustomer),
106            customer_group: Some(ConcessionFeeCustomerGroup::ElectricitySpecialCustomer),
107            value: Some(0.11),
108            currency: Some(Currency::Eur),
109            reference_unit: Some(Unit::KilowattHour),
110            ..Default::default()
111        };
112
113        assert_eq!(
114            fee.customer_group,
115            Some(ConcessionFeeCustomerGroup::ElectricitySpecialCustomer)
116        );
117    }
118
119    #[test]
120    fn test_default() {
121        let fee = ConcessionFee::default();
122        assert!(fee.fee_type.is_none());
123        assert!(fee.value.is_none());
124    }
125
126    #[test]
127    fn test_roundtrip() {
128        let fee = ConcessionFee {
129            fee_type: Some(ConcessionFeeType::TariffCustomer),
130            customer_group: Some(ConcessionFeeCustomerGroup::ElectricityTariff25000),
131            value: Some(1.59),
132            description: Some("Konzessionsabgabe Strom".to_string()),
133            ..Default::default()
134        };
135
136        let json = serde_json::to_string(&fee).unwrap();
137        let parsed: ConcessionFee = serde_json::from_str(&json).unwrap();
138        assert_eq!(fee, parsed);
139    }
140
141    #[test]
142    fn test_bo4e_object_impl() {
143        assert_eq!(ConcessionFee::type_name_german(), "Konzessionsabgabe");
144        assert_eq!(ConcessionFee::type_name_english(), "ConcessionFee");
145    }
146}