bo4e_core/bo/
network_location.rs

1//! Network location (Netzlokation) business object.
2//!
3//! Represents a location in the electricity or gas network.
4
5use serde::{Deserialize, Serialize};
6
7use crate::com::Address;
8use crate::enums::{Division, NetworkLevel};
9use crate::traits::{Bo4eMeta, Bo4eObject};
10
11/// A network location - a point in the electricity or gas network.
12///
13/// German: Netzlokation
14///
15/// A network location represents a physical point in the network
16/// infrastructure where energy flows.
17///
18/// # Example
19///
20/// ```rust
21/// use bo4e_core::bo::NetworkLocation;
22/// use bo4e_core::enums::Division;
23///
24/// let nelo = NetworkLocation {
25///     network_location_id: Some("NELO12345".to_string()),
26///     division: Some(Division::Electricity),
27///     ..Default::default()
28/// };
29/// ```
30#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
31#[serde(rename_all = "camelCase")]
32pub struct NetworkLocation {
33    /// BO4E metadata
34    #[serde(flatten)]
35    pub meta: Bo4eMeta,
36
37    /// Network location ID (Netzlokations-ID)
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub network_location_id: Option<String>,
40
41    /// Energy division (Sparte)
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub division: Option<Division>,
44
45    /// Network level (Netzebene)
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub network_level: Option<NetworkLevel>,
48
49    /// Location address (Adresse)
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub address: Option<Address>,
52
53    /// Network operator code (Netzbetreiber-Codenummer)
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub network_operator_code: Option<String>,
56
57    /// Description (Beschreibung)
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub description: Option<String>,
60
61    /// Associated metering location IDs
62    #[serde(default, skip_serializing_if = "Vec::is_empty")]
63    pub metering_location_ids: Vec<String>,
64
65    /// Associated technical resource IDs
66    #[serde(default, skip_serializing_if = "Vec::is_empty")]
67    pub technical_resource_ids: Vec<String>,
68}
69
70impl Bo4eObject for NetworkLocation {
71    fn type_name_german() -> &'static str {
72        "Netzlokation"
73    }
74
75    fn type_name_english() -> &'static str {
76        "NetworkLocation"
77    }
78
79    fn meta(&self) -> &Bo4eMeta {
80        &self.meta
81    }
82
83    fn meta_mut(&mut self) -> &mut Bo4eMeta {
84        &mut self.meta
85    }
86}
87
88#[cfg(test)]
89mod tests {
90    use super::*;
91
92    #[test]
93    fn test_network_location_creation() {
94        let nelo = NetworkLocation {
95            network_location_id: Some("NELO12345".to_string()),
96            division: Some(Division::Electricity),
97            ..Default::default()
98        };
99
100        assert_eq!(nelo.network_location_id, Some("NELO12345".to_string()));
101    }
102
103    #[test]
104    fn test_serialize() {
105        let nelo = NetworkLocation {
106            meta: Bo4eMeta::with_type("Netzlokation"),
107            network_location_id: Some("NELO12345".to_string()),
108            ..Default::default()
109        };
110
111        let json = serde_json::to_string(&nelo).unwrap();
112        assert!(json.contains(r#""_typ":"Netzlokation""#));
113    }
114
115    #[test]
116    fn test_roundtrip() {
117        let nelo = NetworkLocation {
118            meta: Bo4eMeta::with_type("Netzlokation"),
119            network_location_id: Some("NELO12345".to_string()),
120            division: Some(Division::Electricity),
121            network_level: Some(NetworkLevel::LowVoltage),
122            ..Default::default()
123        };
124
125        let json = serde_json::to_string(&nelo).unwrap();
126        let parsed: NetworkLocation = serde_json::from_str(&json).unwrap();
127        assert_eq!(nelo, parsed);
128    }
129
130    #[test]
131    fn test_bo4e_object_impl() {
132        assert_eq!(NetworkLocation::type_name_german(), "Netzlokation");
133        assert_eq!(NetworkLocation::type_name_english(), "NetworkLocation");
134    }
135}