bo4e_core/bo/
market_participant.rs1use serde::{Deserialize, Serialize};
4
5use crate::com::{Address, ContactMethod};
6use crate::enums::{Division, MarketRole};
7use crate::traits::{Bo4eMeta, Bo4eObject};
8
9#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
27#[serde(rename_all = "camelCase")]
28pub struct MarketParticipant {
29 #[serde(flatten)]
31 pub meta: Bo4eMeta,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
35 pub market_partner_id: Option<String>,
36
37 #[serde(skip_serializing_if = "Option::is_none")]
39 pub name: Option<String>,
40
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub market_role: Option<MarketRole>,
44
45 #[serde(skip_serializing_if = "Option::is_none")]
47 pub division: Option<Division>,
48
49 #[serde(skip_serializing_if = "Option::is_none")]
51 pub address: Option<Address>,
52
53 #[serde(default, skip_serializing_if = "Vec::is_empty")]
55 pub contact_methods: Vec<ContactMethod>,
56
57 #[serde(skip_serializing_if = "Option::is_none")]
59 pub business_partner: Option<Box<super::BusinessPartner>>,
60}
61
62impl Bo4eObject for MarketParticipant {
63 fn type_name_german() -> &'static str {
64 "Marktteilnehmer"
65 }
66
67 fn type_name_english() -> &'static str {
68 "MarketParticipant"
69 }
70
71 fn meta(&self) -> &Bo4eMeta {
72 &self.meta
73 }
74
75 fn meta_mut(&mut self) -> &mut Bo4eMeta {
76 &mut self.meta
77 }
78}
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83
84 #[test]
85 fn test_market_participant_creation() {
86 let participant = MarketParticipant {
87 market_partner_id: Some("9900000000001".to_string()),
88 market_role: Some(MarketRole::Supplier),
89 division: Some(Division::Electricity),
90 ..Default::default()
91 };
92
93 assert_eq!(
94 participant.market_partner_id,
95 Some("9900000000001".to_string())
96 );
97 assert_eq!(participant.market_role, Some(MarketRole::Supplier));
98 }
99
100 #[test]
101 fn test_network_operator() {
102 let participant = MarketParticipant {
103 market_partner_id: Some("9900000000002".to_string()),
104 name: Some("Verteilnetz GmbH".to_string()),
105 market_role: Some(MarketRole::NetworkOperator),
106 division: Some(Division::Electricity),
107 ..Default::default()
108 };
109
110 assert_eq!(participant.market_role, Some(MarketRole::NetworkOperator));
111 }
112
113 #[test]
114 fn test_serialize() {
115 let participant = MarketParticipant {
116 meta: Bo4eMeta::with_type("Marktteilnehmer"),
117 market_partner_id: Some("9900000000001".to_string()),
118 name: Some("Test Lieferant GmbH".to_string()),
119 market_role: Some(MarketRole::Supplier),
120 ..Default::default()
121 };
122
123 let json = serde_json::to_string(&participant).unwrap();
124 assert!(json.contains(r#""marketPartnerId":"9900000000001""#));
125 assert!(json.contains(r#""name":"Test Lieferant GmbH""#));
126 }
127
128 #[test]
129 fn test_roundtrip() {
130 let participant = MarketParticipant {
131 meta: Bo4eMeta::with_type("Marktteilnehmer"),
132 market_partner_id: Some("9900000000001".to_string()),
133 name: Some("Test Lieferant GmbH".to_string()),
134 market_role: Some(MarketRole::Supplier),
135 division: Some(Division::Electricity),
136 ..Default::default()
137 };
138
139 let json = serde_json::to_string(&participant).unwrap();
140 let parsed: MarketParticipant = serde_json::from_str(&json).unwrap();
141 assert_eq!(participant, parsed);
142 }
143
144 #[test]
145 fn test_bo4e_object_impl() {
146 assert_eq!(MarketParticipant::type_name_german(), "Marktteilnehmer");
147 assert_eq!(MarketParticipant::type_name_english(), "MarketParticipant");
148 }
149}