#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "strum",
derive(strum::EnumString, strum::EnumIter, strum::IntoStaticStr)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[non_exhaustive]
pub enum WahlrechtPrognosegrundlage {
#[cfg_attr(feature = "serde", serde(rename = "DURCH_LF"))]
#[cfg_attr(feature = "strum", strum(serialize = "DURCH_LF"))]
DurchLf,
#[cfg_attr(feature = "serde", serde(rename = "DURCH_LF_NICHT_GEGEBEN"))]
#[cfg_attr(feature = "strum", strum(serialize = "DURCH_LF_NICHT_GEGEBEN"))]
DurchLfNichtGegeben,
#[cfg_attr(feature = "serde", serde(rename = "NICHT_WEGEN_GROSSEN_VERBRAUCHS"))]
#[cfg_attr(feature = "strum", strum(serialize = "NICHT_WEGEN_GROSSEN_VERBRAUCHS"))]
NichtWegenGrossenVerbrauchs,
#[cfg_attr(feature = "serde", serde(rename = "NICHT_WEGEN_EIGENVERBRAUCH"))]
#[cfg_attr(feature = "strum", strum(serialize = "NICHT_WEGEN_EIGENVERBRAUCH"))]
NichtWegenEigenverbrauch,
#[cfg_attr(feature = "serde", serde(rename = "NICHT_WEGEN_TAGES_VERBRAUCH"))]
#[cfg_attr(feature = "strum", strum(serialize = "NICHT_WEGEN_TAGES_VERBRAUCH"))]
NichtWegenTagesVerbrauch,
#[cfg_attr(feature = "serde", serde(rename = "NICHT_WEGEN_ENWG"))]
#[cfg_attr(feature = "strum", strum(serialize = "NICHT_WEGEN_ENWG"))]
NichtWegenEnwg,
#[cfg_attr(feature = "serde", serde(other, rename = "UNKNOWN"))]
#[cfg_attr(feature = "strum", strum(serialize = "UNKNOWN"))]
Unknown,
}
impl WahlrechtPrognosegrundlage {
pub const VARIANTS: &'static [Self] = &[
Self::DurchLf,
Self::DurchLfNichtGegeben,
Self::NichtWegenGrossenVerbrauchs,
Self::NichtWegenEigenverbrauch,
Self::NichtWegenTagesVerbrauch,
Self::NichtWegenEnwg,
];
pub const COUNT: usize = Self::VARIANTS.len();
pub fn iter_known() -> impl Iterator<Item = Self> + Clone {
Self::VARIANTS.iter().copied()
}
pub const fn as_wire(&self) -> &'static str {
match self {
Self::DurchLf => "DURCH_LF",
Self::DurchLfNichtGegeben => "DURCH_LF_NICHT_GEGEBEN",
Self::NichtWegenGrossenVerbrauchs => "NICHT_WEGEN_GROSSEN_VERBRAUCHS",
Self::NichtWegenEigenverbrauch => "NICHT_WEGEN_EIGENVERBRAUCH",
Self::NichtWegenTagesVerbrauch => "NICHT_WEGEN_TAGES_VERBRAUCH",
Self::NichtWegenEnwg => "NICHT_WEGEN_ENWG",
Self::Unknown => "UNKNOWN",
}
}
pub fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
match s {
"DURCH_LF" => Ok(Self::DurchLf),
"DURCH_LF_NICHT_GEGEBEN" => Ok(Self::DurchLfNichtGegeben),
"NICHT_WEGEN_GROSSEN_VERBRAUCHS" => Ok(Self::NichtWegenGrossenVerbrauchs),
"NICHT_WEGEN_EIGENVERBRAUCH" => Ok(Self::NichtWegenEigenverbrauch),
"NICHT_WEGEN_TAGES_VERBRAUCH" => Ok(Self::NichtWegenTagesVerbrauch),
"NICHT_WEGEN_ENWG" => Ok(Self::NichtWegenEnwg),
other => Err(crate::error::UnknownVariant::new(other)),
}
}
pub const fn is_unknown(&self) -> bool {
matches!(self, Self::Unknown)
}
pub const fn is_known(&self) -> bool {
!self.is_unknown()
}
}
impl std::fmt::Display for WahlrechtPrognosegrundlage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_wire())
}
}
impl AsRef<str> for WahlrechtPrognosegrundlage {
fn as_ref(&self) -> &str {
self.as_wire()
}
}
#[cfg(feature = "versioned")]
impl crate::bo4e_enum_sealed::Sealed for WahlrechtPrognosegrundlage {}
#[cfg(feature = "versioned")]
impl crate::Bo4eEnum for WahlrechtPrognosegrundlage {
const VARIANTS: &'static [Self] = Self::VARIANTS;
const COUNT: usize = Self::COUNT;
fn as_wire(&self) -> &'static str {
Self::as_wire(self)
}
fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
Self::from_wire(s)
}
fn is_unknown(&self) -> bool {
Self::is_unknown(self)
}
}
#[cfg(feature = "versioned")]
impl crate::Bo4eStrict for WahlrechtPrognosegrundlage {
fn collect_unknown_enums(&self, path: &str, out: &mut Vec<String>) {
if self.is_unknown() {
out.push(path.to_owned());
}
}
}
#[cfg(feature = "sqlx")]
impl sqlx::Type<sqlx::Postgres> for WahlrechtPrognosegrundlage {
fn type_info() -> sqlx::postgres::PgTypeInfo {
<String as sqlx::Type<sqlx::Postgres>>::type_info()
}
}
#[cfg(feature = "sqlx")]
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for WahlrechtPrognosegrundlage {
fn encode_by_ref(
&self,
buf: &mut <sqlx::Postgres as sqlx::Database>::ArgumentBuffer<'q>,
) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
let s: &str = self.as_wire();
<&str as sqlx::Encode<'q, sqlx::Postgres>>::encode_by_ref(&s, buf)
}
}
#[cfg(feature = "sqlx")]
impl<'r> sqlx::Decode<'r, sqlx::Postgres> for WahlrechtPrognosegrundlage {
fn decode(
value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>,
) -> Result<Self, sqlx::error::BoxDynError> {
let s = <&str as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
Ok(Self::from_wire(s).unwrap_or(Self::Unknown))
}
}
#[cfg(test)]
impl proptest::arbitrary::Arbitrary for WahlrechtPrognosegrundlage {
type Parameters = ();
type Strategy = proptest::strategy::BoxedStrategy<Self>;
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
use proptest::prelude::*;
proptest::sample::select(Self::VARIANTS.to_vec()).boxed()
}
}