edi_energy/object_type.rs
1/// Domain type for BDEW object-type qualifier codes (EDIFACT DE 7495).
2///
3/// Used in UTILMD IDE segments to identify the type of the supply-point object.
4/// Prefer this over raw qualifier strings to get compile-time safety and
5/// self-documenting code.
6///
7/// # Example
8/// ```rust
9/// use edi_energy::ObjectType;
10///
11/// let qualifier = ObjectType::Marktlokation.qualifier_code();
12/// assert_eq!(qualifier, "Z18");
13/// ```
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15#[non_exhaustive]
16pub enum ObjectType {
17 /// Marktlokation (`MaLo`) — DE 7495 qualifier `"Z18"`.
18 ///
19 /// A market location is the unit of settlement in the German energy market.
20 /// It aggregates one or more Messlokationen.
21 Marktlokation,
22 /// Messlokation (`MeLo`) — DE 7495 qualifier `"Z19"`.
23 ///
24 /// A measurement location is a physical metering point.
25 Messlokation,
26 /// Tranche — DE 7495 qualifier `"Z30"`.
27 ///
28 /// A tranche is used for load-profile-based settlement.
29 Tranche,
30 /// Netzlokation — DE 7495 qualifier `"Z31"`.
31 ///
32 /// A network location for gas market processes.
33 Netzlokation,
34 /// Technische Ressource — DE 7495 qualifier `"Z32"`.
35 ///
36 /// A technical resource such as a controllable consumer asset.
37 TechnischeRessource,
38 /// Steuerbare Ressource — DE 7495 qualifier `"ZE7"`.
39 ///
40 /// A controllable resource identified by Steuerbarer-Ressourcen-ID.
41 SteuerungRessource,
42}
43
44impl ObjectType {
45 /// Returns the EDIFACT DE 7495 qualifier code for this object type.
46 ///
47 /// ```rust
48 /// use edi_energy::ObjectType;
49 ///
50 /// assert_eq!(ObjectType::Marktlokation.qualifier_code(), "Z18");
51 /// assert_eq!(ObjectType::Messlokation.qualifier_code(), "Z19");
52 /// assert_eq!(ObjectType::Tranche.qualifier_code(), "Z30");
53 /// assert_eq!(ObjectType::Netzlokation.qualifier_code(), "Z31");
54 /// assert_eq!(ObjectType::TechnischeRessource.qualifier_code(), "Z32");
55 /// assert_eq!(ObjectType::SteuerungRessource.qualifier_code(), "ZE7");
56 /// ```
57 #[must_use]
58 pub fn qualifier_code(self) -> &'static str {
59 match self {
60 Self::Marktlokation => "Z18",
61 Self::Messlokation => "Z19",
62 Self::Tranche => "Z30",
63 Self::Netzlokation => "Z31",
64 Self::TechnischeRessource => "Z32",
65 Self::SteuerungRessource => "ZE7",
66 }
67 }
68
69 /// Attempt to parse an `ObjectType` from a raw qualifier code string.
70 ///
71 /// Returns `None` for unknown or extension codes.
72 ///
73 /// ```rust
74 /// use edi_energy::ObjectType;
75 ///
76 /// assert_eq!(ObjectType::from_qualifier_code("Z18"), Some(ObjectType::Marktlokation));
77 /// assert_eq!(ObjectType::from_qualifier_code("Z99"), None);
78 /// ```
79 #[must_use]
80 pub fn from_qualifier_code(code: &str) -> Option<Self> {
81 match code {
82 "Z18" => Some(Self::Marktlokation),
83 "Z19" => Some(Self::Messlokation),
84 "Z30" => Some(Self::Tranche),
85 "Z31" => Some(Self::Netzlokation),
86 "Z32" => Some(Self::TechnischeRessource),
87 "ZE7" => Some(Self::SteuerungRessource),
88 _ => None,
89 }
90 }
91}
92
93impl std::fmt::Display for ObjectType {
94 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95 f.write_str(self.qualifier_code())
96 }
97}
98
99impl From<ObjectType> for String {
100 fn from(ot: ObjectType) -> String {
101 ot.qualifier_code().to_owned()
102 }
103}