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#[serde(rename_all = "camelCase")]
27pub struct ConcessionFee {
28    /// BO4E metadata
29    #[serde(flatten)]
30    pub meta: Bo4eMeta,
31
32    /// Type of concession fee (Konzessionsabgabentyp)
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub fee_type: Option<ConcessionFeeType>,
35
36    /// Customer group for the fee (Kundengruppe KA)
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub customer_group: Option<ConcessionFeeCustomerGroup>,
39
40    /// Fee value (Wert)
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub value: Option<f64>,
43
44    /// Currency (Waehrung)
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub currency: Option<Currency>,
47
48    /// Reference unit (Bezugseinheit)
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub reference_unit: Option<Unit>,
51
52    /// Description (Beschreibung)
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub description: Option<String>,
55}
56
57impl Bo4eObject for ConcessionFee {
58    fn type_name_german() -> &'static str {
59        "Konzessionsabgabe"
60    }
61
62    fn type_name_english() -> &'static str {
63        "ConcessionFee"
64    }
65
66    fn meta(&self) -> &Bo4eMeta {
67        &self.meta
68    }
69
70    fn meta_mut(&mut self) -> &mut Bo4eMeta {
71        &mut self.meta
72    }
73}
74
75#[cfg(test)]
76mod tests {
77    use super::*;
78
79    #[test]
80    fn test_household_concession_fee() {
81        let fee = ConcessionFee {
82            fee_type: Some(ConcessionFeeType::TariffCustomer),
83            customer_group: Some(ConcessionFeeCustomerGroup::ElectricityTariff25000),
84            value: Some(1.59),
85            currency: Some(Currency::Eur),
86            reference_unit: Some(Unit::KilowattHour),
87            ..Default::default()
88        };
89
90        assert_eq!(fee.fee_type, Some(ConcessionFeeType::TariffCustomer));
91        assert_eq!(fee.value, Some(1.59));
92    }
93
94    #[test]
95    fn test_business_concession_fee() {
96        let fee = ConcessionFee {
97            fee_type: Some(ConcessionFeeType::SpecialContractCustomer),
98            customer_group: Some(ConcessionFeeCustomerGroup::ElectricitySpecialCustomer),
99            value: Some(0.11),
100            currency: Some(Currency::Eur),
101            reference_unit: Some(Unit::KilowattHour),
102            ..Default::default()
103        };
104
105        assert_eq!(
106            fee.customer_group,
107            Some(ConcessionFeeCustomerGroup::ElectricitySpecialCustomer)
108        );
109    }
110
111    #[test]
112    fn test_default() {
113        let fee = ConcessionFee::default();
114        assert!(fee.fee_type.is_none());
115        assert!(fee.value.is_none());
116    }
117
118    #[test]
119    fn test_roundtrip() {
120        let fee = ConcessionFee {
121            fee_type: Some(ConcessionFeeType::TariffCustomer),
122            customer_group: Some(ConcessionFeeCustomerGroup::ElectricityTariff25000),
123            value: Some(1.59),
124            description: Some("Konzessionsabgabe Strom".to_string()),
125            ..Default::default()
126        };
127
128        let json = serde_json::to_string(&fee).unwrap();
129        let parsed: ConcessionFee = serde_json::from_str(&json).unwrap();
130        assert_eq!(fee, parsed);
131    }
132
133    #[test]
134    fn test_bo4e_object_impl() {
135        assert_eq!(ConcessionFee::type_name_german(), "Konzessionsabgabe");
136        assert_eq!(ConcessionFee::type_name_english(), "ConcessionFee");
137    }
138}