Skip to main content

rubo4e/generated/v202607/
bo_typ.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3#[cfg_attr(
4    feature = "strum",
5    derive(strum::EnumString, strum::EnumIter, strum::IntoStaticStr)
6)]
7#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
8#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
9/// Auflistung sämtlicher existierender Geschäftsobjekte.
10#[non_exhaustive]
11pub enum BoTyp {
12    #[cfg_attr(feature = "serde", serde(rename = "ANGEBOT"))]
13    #[cfg_attr(feature = "strum", strum(serialize = "ANGEBOT"))]
14    Angebot,
15    #[cfg_attr(feature = "serde", serde(rename = "AUSSCHREIBUNG"))]
16    #[cfg_attr(feature = "strum", strum(serialize = "AUSSCHREIBUNG"))]
17    Ausschreibung,
18    #[cfg_attr(feature = "serde", serde(rename = "BILANZIERUNG"))]
19    #[cfg_attr(feature = "strum", strum(serialize = "BILANZIERUNG"))]
20    Bilanzierung,
21    #[cfg_attr(feature = "serde", serde(rename = "BUENDELVERTRAG"))]
22    #[cfg_attr(feature = "strum", strum(serialize = "BUENDELVERTRAG"))]
23    Buendelvertrag,
24    #[cfg_attr(feature = "serde", serde(rename = "ENERGIEMENGE"))]
25    #[cfg_attr(feature = "strum", strum(serialize = "ENERGIEMENGE"))]
26    Energiemenge,
27    #[cfg_attr(feature = "serde", serde(rename = "FREMDKOSTEN"))]
28    #[cfg_attr(feature = "strum", strum(serialize = "FREMDKOSTEN"))]
29    Fremdkosten,
30    #[cfg_attr(feature = "serde", serde(rename = "GERAET"))]
31    #[cfg_attr(feature = "strum", strum(serialize = "GERAET"))]
32    Geraet,
33    #[cfg_attr(feature = "serde", serde(rename = "GESCHAEFTSOBJEKT"))]
34    #[cfg_attr(feature = "strum", strum(serialize = "GESCHAEFTSOBJEKT"))]
35    Geschaeftsobjekt,
36    #[cfg_attr(feature = "serde", serde(rename = "GESCHAEFTSPARTNER"))]
37    #[cfg_attr(feature = "strum", strum(serialize = "GESCHAEFTSPARTNER"))]
38    Geschaeftspartner,
39    #[cfg_attr(feature = "serde", serde(rename = "KOSTEN"))]
40    #[cfg_attr(feature = "strum", strum(serialize = "KOSTEN"))]
41    Kosten,
42    #[cfg_attr(feature = "serde", serde(rename = "LASTGANG"))]
43    #[cfg_attr(feature = "strum", strum(serialize = "LASTGANG"))]
44    Lastgang,
45    #[cfg_attr(feature = "serde", serde(rename = "MARKTLOKATION"))]
46    #[cfg_attr(feature = "strum", strum(serialize = "MARKTLOKATION"))]
47    Marktlokation,
48    #[cfg_attr(feature = "serde", serde(rename = "MESSLOKATION"))]
49    #[cfg_attr(feature = "strum", strum(serialize = "MESSLOKATION"))]
50    Messlokation,
51    #[cfg_attr(feature = "serde", serde(rename = "NETZLOKATION"))]
52    #[cfg_attr(feature = "strum", strum(serialize = "NETZLOKATION"))]
53    Netzlokation,
54    #[cfg_attr(feature = "serde", serde(rename = "MARKTTEILNEHMER"))]
55    #[cfg_attr(feature = "strum", strum(serialize = "MARKTTEILNEHMER"))]
56    Marktteilnehmer,
57    #[cfg_attr(feature = "serde", serde(rename = "NETZNUTZUNGSRECHNUNG"))]
58    #[cfg_attr(feature = "strum", strum(serialize = "NETZNUTZUNGSRECHNUNG"))]
59    Netznutzungsrechnung,
60    #[cfg_attr(feature = "serde", serde(rename = "TECHNISCHERESSOURCE"))]
61    #[cfg_attr(feature = "strum", strum(serialize = "TECHNISCHERESSOURCE"))]
62    TechnischeRessource,
63    #[cfg_attr(feature = "serde", serde(rename = "STEUERBARERESSOURCE"))]
64    #[cfg_attr(feature = "strum", strum(serialize = "STEUERBARERESSOURCE"))]
65    SteuerbareRessource,
66    #[cfg_attr(feature = "serde", serde(rename = "PERSON"))]
67    #[cfg_attr(feature = "strum", strum(serialize = "PERSON"))]
68    Person,
69    #[cfg_attr(feature = "serde", serde(rename = "PREISBLATT"))]
70    #[cfg_attr(feature = "strum", strum(serialize = "PREISBLATT"))]
71    Preisblatt,
72    #[cfg_attr(feature = "serde", serde(rename = "PREISBLATTDIENSTLEISTUNG"))]
73    #[cfg_attr(feature = "strum", strum(serialize = "PREISBLATTDIENSTLEISTUNG"))]
74    PreisblattDienstleistung,
75    #[cfg_attr(feature = "serde", serde(rename = "PREISBLATTHARDWARE"))]
76    #[cfg_attr(feature = "strum", strum(serialize = "PREISBLATTHARDWARE"))]
77    PreisblattHardware,
78    #[cfg_attr(feature = "serde", serde(rename = "PREISBLATTKONZESSIONSABGABE"))]
79    #[cfg_attr(feature = "strum", strum(serialize = "PREISBLATTKONZESSIONSABGABE"))]
80    PreisblattKonzessionsabgabe,
81    #[cfg_attr(feature = "serde", serde(rename = "PREISBLATTMESSUNG"))]
82    #[cfg_attr(feature = "strum", strum(serialize = "PREISBLATTMESSUNG"))]
83    PreisblattMessung,
84    #[cfg_attr(feature = "serde", serde(rename = "PREISBLATTNETZNUTZUNG"))]
85    #[cfg_attr(feature = "strum", strum(serialize = "PREISBLATTNETZNUTZUNG"))]
86    PreisblattNetznutzung,
87    #[cfg_attr(feature = "serde", serde(rename = "PREISBLATTUMLAGEN"))]
88    #[cfg_attr(feature = "strum", strum(serialize = "PREISBLATTUMLAGEN"))]
89    Preisblattumlagen,
90    #[cfg_attr(feature = "serde", serde(rename = "RECHNUNG"))]
91    #[cfg_attr(feature = "strum", strum(serialize = "RECHNUNG"))]
92    Rechnung,
93    #[cfg_attr(feature = "serde", serde(rename = "REGION"))]
94    #[cfg_attr(feature = "strum", strum(serialize = "REGION"))]
95    Region,
96    #[cfg_attr(feature = "serde", serde(rename = "STANDORTEIGENSCHAFTEN"))]
97    #[cfg_attr(feature = "strum", strum(serialize = "STANDORTEIGENSCHAFTEN"))]
98    Standorteigenschaften,
99    #[cfg_attr(feature = "serde", serde(rename = "TARIF"))]
100    #[cfg_attr(feature = "strum", strum(serialize = "TARIF"))]
101    Tarif,
102    #[cfg_attr(feature = "serde", serde(rename = "TARIFINFO"))]
103    #[cfg_attr(feature = "strum", strum(serialize = "TARIFINFO"))]
104    Tarifinfo,
105    #[cfg_attr(feature = "serde", serde(rename = "TARIFKOSTEN"))]
106    #[cfg_attr(feature = "strum", strum(serialize = "TARIFKOSTEN"))]
107    Tarifkosten,
108    #[cfg_attr(feature = "serde", serde(rename = "TARIFPREISBLATT"))]
109    #[cfg_attr(feature = "strum", strum(serialize = "TARIFPREISBLATT"))]
110    Tarifpreisblatt,
111    #[cfg_attr(feature = "serde", serde(rename = "VERTRAG"))]
112    #[cfg_attr(feature = "strum", strum(serialize = "VERTRAG"))]
113    Vertrag,
114    #[cfg_attr(feature = "serde", serde(rename = "ZAEHLER"))]
115    #[cfg_attr(feature = "strum", strum(serialize = "ZAEHLER"))]
116    Zaehler,
117    #[cfg_attr(feature = "serde", serde(rename = "ZAEHLZEITDEFINITION"))]
118    #[cfg_attr(feature = "strum", strum(serialize = "ZAEHLZEITDEFINITION"))]
119    Zaehlzeitdefinition,
120    #[cfg_attr(feature = "serde", serde(rename = "ZEITREIHE"))]
121    #[cfg_attr(feature = "strum", strum(serialize = "ZEITREIHE"))]
122    Zeitreihe,
123    #[cfg_attr(feature = "serde", serde(rename = "LOKATIONSZUORDNUNG"))]
124    #[cfg_attr(feature = "strum", strum(serialize = "LOKATIONSZUORDNUNG"))]
125    Lokationszuordnung,
126    /// Unknown or future variant — produced when deserializing a value
127    /// that is not yet known to this version of the library.
128    #[cfg_attr(feature = "serde", serde(other, rename = "UNKNOWN"))]
129    #[cfg_attr(feature = "strum", strum(serialize = "UNKNOWN"))]
130    Unknown,
131}
132impl BoTyp {
133    /// All variants defined by the BO4E schema, in declaration order.
134    ///
135    /// Excludes the forward-compatibility [`BoTyp::Unknown`] catch-all, so this
136    /// is exactly the set of values that appear on the wire.  Available **without**
137    /// the `strum` feature — use it to drift-guard SQL `CHECK` lists and mappings.
138    pub const VARIANTS: &'static [Self] = &[
139        Self::Angebot,
140        Self::Ausschreibung,
141        Self::Bilanzierung,
142        Self::Buendelvertrag,
143        Self::Energiemenge,
144        Self::Fremdkosten,
145        Self::Geraet,
146        Self::Geschaeftsobjekt,
147        Self::Geschaeftspartner,
148        Self::Kosten,
149        Self::Lastgang,
150        Self::Marktlokation,
151        Self::Messlokation,
152        Self::Netzlokation,
153        Self::Marktteilnehmer,
154        Self::Netznutzungsrechnung,
155        Self::TechnischeRessource,
156        Self::SteuerbareRessource,
157        Self::Person,
158        Self::Preisblatt,
159        Self::PreisblattDienstleistung,
160        Self::PreisblattHardware,
161        Self::PreisblattKonzessionsabgabe,
162        Self::PreisblattMessung,
163        Self::PreisblattNetznutzung,
164        Self::Preisblattumlagen,
165        Self::Rechnung,
166        Self::Region,
167        Self::Standorteigenschaften,
168        Self::Tarif,
169        Self::Tarifinfo,
170        Self::Tarifkosten,
171        Self::Tarifpreisblatt,
172        Self::Vertrag,
173        Self::Zaehler,
174        Self::Zaehlzeitdefinition,
175        Self::Zeitreihe,
176        Self::Lokationszuordnung,
177    ];
178    /// Number of schema-defined variants (equal to `VARIANTS.len()`), excluding the
179    /// [`BoTyp::Unknown`] catch-all.  Stable for this schema version.
180    pub const COUNT: usize = Self::VARIANTS.len();
181    /// Returns an iterator over all **known** variants of `BoTyp`.
182    ///
183    /// Yields only variants that correspond to values defined in the BO4E schema
184    /// (i.e. [`Self::VARIANTS`]), never the [`BoTyp::Unknown`] catch-all.
185    /// Available **without** the `strum` feature.
186    ///
187    /// # Example
188    /// ```
189    /// # use rubo4e::current::BoTyp;
190    /// // Never yields the `Unknown` catch-all, so the count matches `COUNT`.
191    /// assert_eq!(BoTyp::iter_known().count(), BoTyp::COUNT);
192    /// assert!(BoTyp::iter_known().all(|v| v.is_known()));
193    /// ```
194    pub fn iter_known() -> impl Iterator<Item = Self> + Clone {
195        Self::VARIANTS.iter().copied()
196    }
197    /// Returns the canonical BO4E wire string (SCREAMING_SNAKE_CASE) for this value.
198    ///
199    /// [`BoTyp::Unknown`] renders as `"UNKNOWN"`, matching its serialized form.
200    pub const fn as_wire(&self) -> &'static str {
201        match self {
202            Self::Angebot => "ANGEBOT",
203            Self::Ausschreibung => "AUSSCHREIBUNG",
204            Self::Bilanzierung => "BILANZIERUNG",
205            Self::Buendelvertrag => "BUENDELVERTRAG",
206            Self::Energiemenge => "ENERGIEMENGE",
207            Self::Fremdkosten => "FREMDKOSTEN",
208            Self::Geraet => "GERAET",
209            Self::Geschaeftsobjekt => "GESCHAEFTSOBJEKT",
210            Self::Geschaeftspartner => "GESCHAEFTSPARTNER",
211            Self::Kosten => "KOSTEN",
212            Self::Lastgang => "LASTGANG",
213            Self::Marktlokation => "MARKTLOKATION",
214            Self::Messlokation => "MESSLOKATION",
215            Self::Netzlokation => "NETZLOKATION",
216            Self::Marktteilnehmer => "MARKTTEILNEHMER",
217            Self::Netznutzungsrechnung => "NETZNUTZUNGSRECHNUNG",
218            Self::TechnischeRessource => "TECHNISCHERESSOURCE",
219            Self::SteuerbareRessource => "STEUERBARERESSOURCE",
220            Self::Person => "PERSON",
221            Self::Preisblatt => "PREISBLATT",
222            Self::PreisblattDienstleistung => "PREISBLATTDIENSTLEISTUNG",
223            Self::PreisblattHardware => "PREISBLATTHARDWARE",
224            Self::PreisblattKonzessionsabgabe => "PREISBLATTKONZESSIONSABGABE",
225            Self::PreisblattMessung => "PREISBLATTMESSUNG",
226            Self::PreisblattNetznutzung => "PREISBLATTNETZNUTZUNG",
227            Self::Preisblattumlagen => "PREISBLATTUMLAGEN",
228            Self::Rechnung => "RECHNUNG",
229            Self::Region => "REGION",
230            Self::Standorteigenschaften => "STANDORTEIGENSCHAFTEN",
231            Self::Tarif => "TARIF",
232            Self::Tarifinfo => "TARIFINFO",
233            Self::Tarifkosten => "TARIFKOSTEN",
234            Self::Tarifpreisblatt => "TARIFPREISBLATT",
235            Self::Vertrag => "VERTRAG",
236            Self::Zaehler => "ZAEHLER",
237            Self::Zaehlzeitdefinition => "ZAEHLZEITDEFINITION",
238            Self::Zeitreihe => "ZEITREIHE",
239            Self::Lokationszuordnung => "LOKATIONSZUORDNUNG",
240            Self::Unknown => "UNKNOWN",
241        }
242    }
243    /// **Strictly** parses a BO4E wire string into a known variant.
244    ///
245    /// Unlike the lenient `serde` / [`FromStr`](std::str::FromStr) path — which maps
246    /// any unrecognized value (a typo, a legacy code, or a value from a newer schema)
247    /// to [`BoTyp::Unknown`] — this returns
248    /// [`Err`](crate::error::UnknownVariant) for values not defined in this schema
249    /// version, including the literal `"UNKNOWN"`.  Use it at the ingest boundary to
250    /// reject bad values instead of silently degrading them.
251    ///
252    /// # Example
253    /// ```
254    /// # use rubo4e::current::BoTyp;
255    /// assert_eq!(BoTyp::from_wire("ANGEBOT"), Ok(BoTyp::Angebot));
256    /// // Out-of-schema values are rejected rather than degraded:
257    /// assert!(BoTyp::from_wire("NOT_A_REAL_VALUE").is_err());
258    /// // …including the `Unknown` catch-all's own wire spelling:
259    /// assert!(BoTyp::from_wire("UNKNOWN").is_err());
260    /// ```
261    pub fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
262        match s {
263            "ANGEBOT" => Ok(Self::Angebot),
264            "AUSSCHREIBUNG" => Ok(Self::Ausschreibung),
265            "BILANZIERUNG" => Ok(Self::Bilanzierung),
266            "BUENDELVERTRAG" => Ok(Self::Buendelvertrag),
267            "ENERGIEMENGE" => Ok(Self::Energiemenge),
268            "FREMDKOSTEN" => Ok(Self::Fremdkosten),
269            "GERAET" => Ok(Self::Geraet),
270            "GESCHAEFTSOBJEKT" => Ok(Self::Geschaeftsobjekt),
271            "GESCHAEFTSPARTNER" => Ok(Self::Geschaeftspartner),
272            "KOSTEN" => Ok(Self::Kosten),
273            "LASTGANG" => Ok(Self::Lastgang),
274            "MARKTLOKATION" => Ok(Self::Marktlokation),
275            "MESSLOKATION" => Ok(Self::Messlokation),
276            "NETZLOKATION" => Ok(Self::Netzlokation),
277            "MARKTTEILNEHMER" => Ok(Self::Marktteilnehmer),
278            "NETZNUTZUNGSRECHNUNG" => Ok(Self::Netznutzungsrechnung),
279            "TECHNISCHERESSOURCE" => Ok(Self::TechnischeRessource),
280            "STEUERBARERESSOURCE" => Ok(Self::SteuerbareRessource),
281            "PERSON" => Ok(Self::Person),
282            "PREISBLATT" => Ok(Self::Preisblatt),
283            "PREISBLATTDIENSTLEISTUNG" => Ok(Self::PreisblattDienstleistung),
284            "PREISBLATTHARDWARE" => Ok(Self::PreisblattHardware),
285            "PREISBLATTKONZESSIONSABGABE" => Ok(Self::PreisblattKonzessionsabgabe),
286            "PREISBLATTMESSUNG" => Ok(Self::PreisblattMessung),
287            "PREISBLATTNETZNUTZUNG" => Ok(Self::PreisblattNetznutzung),
288            "PREISBLATTUMLAGEN" => Ok(Self::Preisblattumlagen),
289            "RECHNUNG" => Ok(Self::Rechnung),
290            "REGION" => Ok(Self::Region),
291            "STANDORTEIGENSCHAFTEN" => Ok(Self::Standorteigenschaften),
292            "TARIF" => Ok(Self::Tarif),
293            "TARIFINFO" => Ok(Self::Tarifinfo),
294            "TARIFKOSTEN" => Ok(Self::Tarifkosten),
295            "TARIFPREISBLATT" => Ok(Self::Tarifpreisblatt),
296            "VERTRAG" => Ok(Self::Vertrag),
297            "ZAEHLER" => Ok(Self::Zaehler),
298            "ZAEHLZEITDEFINITION" => Ok(Self::Zaehlzeitdefinition),
299            "ZEITREIHE" => Ok(Self::Zeitreihe),
300            "LOKATIONSZUORDNUNG" => Ok(Self::Lokationszuordnung),
301            other => Err(crate::error::UnknownVariant::new(other)),
302        }
303    }
304    /// Returns `true` if this value is the forward-compatibility
305    /// [`BoTyp::Unknown`] catch-all (an out-of-schema value).
306    pub const fn is_unknown(&self) -> bool {
307        matches!(self, Self::Unknown)
308    }
309    /// Returns `true` if this value is a known, schema-defined variant.
310    pub const fn is_known(&self) -> bool {
311        !self.is_unknown()
312    }
313}
314impl std::fmt::Display for BoTyp {
315    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
316        f.write_str(self.as_wire())
317    }
318}
319impl AsRef<str> for BoTyp {
320    fn as_ref(&self) -> &str {
321        self.as_wire()
322    }
323}
324#[cfg(feature = "versioned")]
325impl crate::bo4e_enum_sealed::Sealed for BoTyp {}
326#[cfg(feature = "versioned")]
327impl crate::Bo4eEnum for BoTyp {
328    const VARIANTS: &'static [Self] = Self::VARIANTS;
329    const COUNT: usize = Self::COUNT;
330    fn as_wire(&self) -> &'static str {
331        Self::as_wire(self)
332    }
333    fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
334        Self::from_wire(s)
335    }
336    fn is_unknown(&self) -> bool {
337        Self::is_unknown(self)
338    }
339}
340#[cfg(feature = "versioned")]
341impl crate::Bo4eStrict for BoTyp {
342    fn collect_unknown_enums(&self, path: &str, out: &mut Vec<String>) {
343        if self.is_unknown() {
344            out.push(path.to_owned());
345        }
346    }
347}
348#[cfg(feature = "sqlx")]
349impl sqlx::Type<sqlx::Postgres> for BoTyp {
350    fn type_info() -> sqlx::postgres::PgTypeInfo {
351        <String as sqlx::Type<sqlx::Postgres>>::type_info()
352    }
353}
354/// Encodes as the canonical BO4E wire string, borrowed from `as_wire` — no
355/// intermediate `String` or `serde_json::Value` is allocated.
356#[cfg(feature = "sqlx")]
357impl<'q> sqlx::Encode<'q, sqlx::Postgres> for BoTyp {
358    fn encode_by_ref(
359        &self,
360        buf: &mut <sqlx::Postgres as sqlx::Database>::ArgumentBuffer<'q>,
361    ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
362        let s: &str = self.as_wire();
363        <&str as sqlx::Encode<'q, sqlx::Postgres>>::encode_by_ref(&s, buf)
364    }
365}
366/// Decodes leniently, matching the `serde` path: a value the schema does not
367/// define becomes [`BoTyp::Unknown`] rather than a decode error, so a
368/// database row written by a newer schema version still reads back.
369///
370/// Use [`BoTyp::from_wire`] on a `String` column, or check
371/// [`BoTyp::is_known`], where out-of-schema values must be rejected.
372#[cfg(feature = "sqlx")]
373impl<'r> sqlx::Decode<'r, sqlx::Postgres> for BoTyp {
374    fn decode(
375        value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>,
376    ) -> Result<Self, sqlx::error::BoxDynError> {
377        let s = <&str as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
378        Ok(Self::from_wire(s).unwrap_or(Self::Unknown))
379    }
380}
381/// Lets `Vec<BoTyp>` bind to a `TEXT[]` column.  Only this crate can
382/// provide it: the trait and the enum are both foreign to any consumer, so the
383/// orphan rule rules out a downstream impl.
384#[cfg(feature = "sqlx")]
385impl sqlx::postgres::PgHasArrayType for BoTyp {
386    fn array_type_info() -> sqlx::postgres::PgTypeInfo {
387        <String as sqlx::postgres::PgHasArrayType>::array_type_info()
388    }
389}
390#[cfg(test)]
391impl proptest::arbitrary::Arbitrary for BoTyp {
392    type Parameters = ();
393    type Strategy = proptest::strategy::BoxedStrategy<Self>;
394    fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
395        use proptest::prelude::*;
396        proptest::sample::select(Self::VARIANTS.to_vec()).boxed()
397    }
398}