Skip to main content

edi_energy/
message_type.rs

1use std::fmt;
2
3/// EDIFACT message type codes used in the German energy market (EDI@Energy).
4///
5/// All variants are always present regardless of enabled features; feature gates
6/// control which concrete message structs and profile data are compiled in.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[non_exhaustive]
9pub enum MessageType {
10    /// UTILMD — Utilities Master Data.\
11    /// BDEW message for grid-connection processes (switchover, registration, etc.).
12    Utilmd,
13    /// MSCONS — Metered Services Consumption Report.\
14    /// Meter value transmission between grid operator and balance-group manager.
15    Mscons,
16    /// APERAK — Application Error and Acknowledgement.\
17    /// Technical rejection or acknowledgement of a previously received message.
18    Aperak,
19    /// CONTRL — Interchange Control Structure.\
20    /// Syntax acknowledgement at interchange level.
21    Contrl,
22    /// INVOIC — Invoice.
23    Invoic,
24    /// REMADV — Remittance Advice.
25    Remadv,
26    /// ORDERS — Purchase Order.
27    Orders,
28    /// IFTSTA — International Multimodal Status Report Message.
29    Iftsta,
30    /// INSRPT — Inspection Report.
31    Insrpt,
32    /// REQOTE — Request for Quotation.
33    Reqote,
34    /// PARTIN — Party Information.
35    Partin,
36    /// ORDCHG — Purchase Order Change.
37    Ordchg,
38    /// ORDRSP — Purchase Order Response.
39    Ordrsp,
40    /// QUOTES — Quotation.
41    Quotes,
42    /// COMDIS — Commercial Dispute (Handelsunstimmigkeit).
43    Comdis,
44    /// PRICAT — Price/Sales Catalogue (Preisliste).
45    Pricat,
46    /// UTILTS — Übertragung technischer Stammdaten (Technical Master Data).
47    Utilts,
48}
49
50impl MessageType {
51    /// Returns the EDIFACT type code as it appears in the UNH segment (e.g. `"UTILMD"`).
52    #[must_use]
53    pub fn as_str(self) -> &'static str {
54        match self {
55            Self::Utilmd => "UTILMD",
56            Self::Mscons => "MSCONS",
57            Self::Aperak => "APERAK",
58            Self::Contrl => "CONTRL",
59            Self::Invoic => "INVOIC",
60            Self::Remadv => "REMADV",
61            Self::Orders => "ORDERS",
62            Self::Iftsta => "IFTSTA",
63            Self::Insrpt => "INSRPT",
64            Self::Reqote => "REQOTE",
65            Self::Partin => "PARTIN",
66            Self::Ordchg => "ORDCHG",
67            Self::Ordrsp => "ORDRSP",
68            Self::Quotes => "QUOTES",
69            Self::Comdis => "COMDIS",
70            Self::Pricat => "PRICAT",
71            Self::Utilts => "UTILTS",
72        }
73    }
74
75    /// Parses the type code from a UNH segment string slice.
76    ///
77    /// Returns `None` for unrecognised codes.
78    #[must_use]
79    pub fn from_unh_code(code: &str) -> Option<Self> {
80        match code {
81            "UTILMD" => Some(Self::Utilmd),
82            "MSCONS" => Some(Self::Mscons),
83            "APERAK" => Some(Self::Aperak),
84            "CONTRL" => Some(Self::Contrl),
85            "INVOIC" => Some(Self::Invoic),
86            "REMADV" => Some(Self::Remadv),
87            "ORDERS" => Some(Self::Orders),
88            "IFTSTA" => Some(Self::Iftsta),
89            "INSRPT" => Some(Self::Insrpt),
90            "REQOTE" => Some(Self::Reqote),
91            "PARTIN" => Some(Self::Partin),
92            "ORDCHG" => Some(Self::Ordchg),
93            "ORDRSP" => Some(Self::Ordrsp),
94            "QUOTES" => Some(Self::Quotes),
95            "COMDIS" => Some(Self::Comdis),
96            "PRICAT" => Some(Self::Pricat),
97            "UTILTS" => Some(Self::Utilts),
98            _ => None,
99        }
100    }
101}
102
103impl fmt::Display for MessageType {
104    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105        f.write_str(self.as_str())
106    }
107}