Skip to main content

rubo4e/generated/v202607/
ausschreibungsstatus.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/// Bezeichnungen für die Ausschreibungsphasen
10#[non_exhaustive]
11pub enum Ausschreibungsstatus {
12    #[cfg_attr(feature = "serde", serde(rename = "PHASE1"))]
13    #[cfg_attr(feature = "strum", strum(serialize = "PHASE1"))]
14    Phase1,
15    #[cfg_attr(feature = "serde", serde(rename = "PHASE2"))]
16    #[cfg_attr(feature = "strum", strum(serialize = "PHASE2"))]
17    Phase2,
18    #[cfg_attr(feature = "serde", serde(rename = "PHASE3"))]
19    #[cfg_attr(feature = "strum", strum(serialize = "PHASE3"))]
20    Phase3,
21    #[cfg_attr(feature = "serde", serde(rename = "PHASE4"))]
22    #[cfg_attr(feature = "strum", strum(serialize = "PHASE4"))]
23    Phase4,
24    /// Unknown or future variant — produced when deserializing a value
25    /// that is not yet known to this version of the library.
26    #[cfg_attr(feature = "serde", serde(other, rename = "UNKNOWN"))]
27    #[cfg_attr(feature = "strum", strum(serialize = "UNKNOWN"))]
28    Unknown,
29}
30impl Ausschreibungsstatus {
31    /// All variants defined by the BO4E schema, in declaration order.
32    ///
33    /// Excludes the forward-compatibility [`Ausschreibungsstatus::Unknown`] catch-all, so this
34    /// is exactly the set of values that appear on the wire.  Available **without**
35    /// the `strum` feature — use it to drift-guard SQL `CHECK` lists and mappings.
36    pub const VARIANTS: &'static [Self] = &[Self::Phase1, Self::Phase2, Self::Phase3, Self::Phase4];
37    /// Number of schema-defined variants (equal to `VARIANTS.len()`), excluding the
38    /// [`Ausschreibungsstatus::Unknown`] catch-all.  Stable for this schema version.
39    pub const COUNT: usize = Self::VARIANTS.len();
40    /// Returns an iterator over all **known** variants of `Ausschreibungsstatus`.
41    ///
42    /// Yields only variants that correspond to values defined in the BO4E schema
43    /// (i.e. [`Self::VARIANTS`]), never the [`Ausschreibungsstatus::Unknown`] catch-all.
44    /// Available **without** the `strum` feature.
45    ///
46    /// # Example
47    /// ```
48    /// # use rubo4e::current::Ausschreibungsstatus;
49    /// // Never yields the `Unknown` catch-all, so the count matches `COUNT`.
50    /// assert_eq!(Ausschreibungsstatus::iter_known().count(), Ausschreibungsstatus::COUNT);
51    /// assert!(Ausschreibungsstatus::iter_known().all(|v| v.is_known()));
52    /// ```
53    pub fn iter_known() -> impl Iterator<Item = Self> + Clone {
54        Self::VARIANTS.iter().copied()
55    }
56    /// Returns the canonical BO4E wire string (SCREAMING_SNAKE_CASE) for this value.
57    ///
58    /// [`Ausschreibungsstatus::Unknown`] renders as `"UNKNOWN"`, matching its serialized form.
59    pub const fn as_wire(&self) -> &'static str {
60        match self {
61            Self::Phase1 => "PHASE1",
62            Self::Phase2 => "PHASE2",
63            Self::Phase3 => "PHASE3",
64            Self::Phase4 => "PHASE4",
65            Self::Unknown => "UNKNOWN",
66        }
67    }
68    /// **Strictly** parses a BO4E wire string into a known variant.
69    ///
70    /// Unlike the lenient `serde` / [`FromStr`](std::str::FromStr) path — which maps
71    /// any unrecognized value (a typo, a legacy code, or a value from a newer schema)
72    /// to [`Ausschreibungsstatus::Unknown`] — this returns
73    /// [`Err`](crate::error::UnknownVariant) for values not defined in this schema
74    /// version, including the literal `"UNKNOWN"`.  Use it at the ingest boundary to
75    /// reject bad values instead of silently degrading them.
76    ///
77    /// # Example
78    /// ```
79    /// # use rubo4e::current::Ausschreibungsstatus;
80    /// assert_eq!(Ausschreibungsstatus::from_wire("PHASE1"), Ok(Ausschreibungsstatus::Phase1));
81    /// // Out-of-schema values are rejected rather than degraded:
82    /// assert!(Ausschreibungsstatus::from_wire("NOT_A_REAL_VALUE").is_err());
83    /// // …including the `Unknown` catch-all's own wire spelling:
84    /// assert!(Ausschreibungsstatus::from_wire("UNKNOWN").is_err());
85    /// ```
86    pub fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
87        match s {
88            "PHASE1" => Ok(Self::Phase1),
89            "PHASE2" => Ok(Self::Phase2),
90            "PHASE3" => Ok(Self::Phase3),
91            "PHASE4" => Ok(Self::Phase4),
92            other => Err(crate::error::UnknownVariant::new(other)),
93        }
94    }
95    /// Returns `true` if this value is the forward-compatibility
96    /// [`Ausschreibungsstatus::Unknown`] catch-all (an out-of-schema value).
97    pub const fn is_unknown(&self) -> bool {
98        matches!(self, Self::Unknown)
99    }
100    /// Returns `true` if this value is a known, schema-defined variant.
101    pub const fn is_known(&self) -> bool {
102        !self.is_unknown()
103    }
104}
105impl std::fmt::Display for Ausschreibungsstatus {
106    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107        f.write_str(self.as_wire())
108    }
109}
110impl AsRef<str> for Ausschreibungsstatus {
111    fn as_ref(&self) -> &str {
112        self.as_wire()
113    }
114}
115#[cfg(feature = "versioned")]
116impl crate::bo4e_enum_sealed::Sealed for Ausschreibungsstatus {}
117#[cfg(feature = "versioned")]
118impl crate::Bo4eEnum for Ausschreibungsstatus {
119    const VARIANTS: &'static [Self] = Self::VARIANTS;
120    const COUNT: usize = Self::COUNT;
121    fn as_wire(&self) -> &'static str {
122        Self::as_wire(self)
123    }
124    fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
125        Self::from_wire(s)
126    }
127    fn is_unknown(&self) -> bool {
128        Self::is_unknown(self)
129    }
130}
131#[cfg(feature = "versioned")]
132impl crate::Bo4eStrict for Ausschreibungsstatus {
133    fn collect_unknown_enums(&self, path: &str, out: &mut Vec<String>) {
134        if self.is_unknown() {
135            out.push(path.to_owned());
136        }
137    }
138}
139#[cfg(feature = "sqlx")]
140impl sqlx::Type<sqlx::Postgres> for Ausschreibungsstatus {
141    fn type_info() -> sqlx::postgres::PgTypeInfo {
142        <String as sqlx::Type<sqlx::Postgres>>::type_info()
143    }
144}
145/// Encodes as the canonical BO4E wire string, borrowed from `as_wire` — no
146/// intermediate `String` or `serde_json::Value` is allocated.
147#[cfg(feature = "sqlx")]
148impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Ausschreibungsstatus {
149    fn encode_by_ref(
150        &self,
151        buf: &mut <sqlx::Postgres as sqlx::Database>::ArgumentBuffer<'q>,
152    ) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
153        let s: &str = self.as_wire();
154        <&str as sqlx::Encode<'q, sqlx::Postgres>>::encode_by_ref(&s, buf)
155    }
156}
157/// Decodes leniently, matching the `serde` path: a value the schema does not
158/// define becomes [`Ausschreibungsstatus::Unknown`] rather than a decode error, so a
159/// database row written by a newer schema version still reads back.
160///
161/// Use [`Ausschreibungsstatus::from_wire`] on a `String` column, or check
162/// [`Ausschreibungsstatus::is_known`], where out-of-schema values must be rejected.
163#[cfg(feature = "sqlx")]
164impl<'r> sqlx::Decode<'r, sqlx::Postgres> for Ausschreibungsstatus {
165    fn decode(
166        value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>,
167    ) -> Result<Self, sqlx::error::BoxDynError> {
168        let s = <&str as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
169        Ok(Self::from_wire(s).unwrap_or(Self::Unknown))
170    }
171}
172/// Lets `Vec<Ausschreibungsstatus>` bind to a `TEXT[]` column.  Only this crate can
173/// provide it: the trait and the enum are both foreign to any consumer, so the
174/// orphan rule rules out a downstream impl.
175#[cfg(feature = "sqlx")]
176impl sqlx::postgres::PgHasArrayType for Ausschreibungsstatus {
177    fn array_type_info() -> sqlx::postgres::PgTypeInfo {
178        <String as sqlx::postgres::PgHasArrayType>::array_type_info()
179    }
180}
181#[cfg(test)]
182impl proptest::arbitrary::Arbitrary for Ausschreibungsstatus {
183    type Parameters = ();
184    type Strategy = proptest::strategy::BoxedStrategy<Self>;
185    fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
186        use proptest::prelude::*;
187        proptest::sample::select(Self::VARIANTS.to_vec()).boxed()
188    }
189}