#[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 Kundentyp {
#[cfg_attr(feature = "serde", serde(rename = "GEWERBE"))]
#[cfg_attr(feature = "strum", strum(serialize = "GEWERBE"))]
Gewerbe,
#[cfg_attr(feature = "serde", serde(rename = "PRIVAT"))]
#[cfg_attr(feature = "strum", strum(serialize = "PRIVAT"))]
Privat,
#[cfg_attr(feature = "serde", serde(rename = "LANDWIRT"))]
#[cfg_attr(feature = "strum", strum(serialize = "LANDWIRT"))]
Landwirt,
#[cfg_attr(feature = "serde", serde(rename = "SONSTIGE"))]
#[cfg_attr(feature = "strum", strum(serialize = "SONSTIGE"))]
Sonstige,
#[cfg_attr(feature = "serde", serde(rename = "HAUSHALT"))]
#[cfg_attr(feature = "strum", strum(serialize = "HAUSHALT"))]
Haushalt,
#[cfg_attr(feature = "serde", serde(rename = "DIREKTHEIZUNG"))]
#[cfg_attr(feature = "strum", strum(serialize = "DIREKTHEIZUNG"))]
Direktheizung,
#[cfg_attr(feature = "serde", serde(rename = "GEMEINSCHAFT_MFH"))]
#[cfg_attr(feature = "strum", strum(serialize = "GEMEINSCHAFT_MFH"))]
GemeinschaftMfh,
#[cfg_attr(feature = "serde", serde(rename = "KIRCHE"))]
#[cfg_attr(feature = "strum", strum(serialize = "KIRCHE"))]
Kirche,
#[cfg_attr(feature = "serde", serde(rename = "KWK"))]
#[cfg_attr(feature = "strum", strum(serialize = "KWK"))]
Kwk,
#[cfg_attr(feature = "serde", serde(rename = "LADESAEULE"))]
#[cfg_attr(feature = "strum", strum(serialize = "LADESAEULE"))]
Ladesaeule,
#[cfg_attr(feature = "serde", serde(rename = "BELEUCHTUNG_OEFFENTLICH"))]
#[cfg_attr(feature = "strum", strum(serialize = "BELEUCHTUNG_OEFFENTLICH"))]
BeleuchtungOeffentlich,
#[cfg_attr(feature = "serde", serde(rename = "BELEUCHTUNG_STRASSE"))]
#[cfg_attr(feature = "strum", strum(serialize = "BELEUCHTUNG_STRASSE"))]
BeleuchtungStrasse,
#[cfg_attr(feature = "serde", serde(rename = "SPEICHERHEIZUNG"))]
#[cfg_attr(feature = "strum", strum(serialize = "SPEICHERHEIZUNG"))]
Speicherheizung,
#[cfg_attr(feature = "serde", serde(rename = "UNTERBR_EINRICHTUNG"))]
#[cfg_attr(feature = "strum", strum(serialize = "UNTERBR_EINRICHTUNG"))]
UnterbrEinrichtung,
#[cfg_attr(feature = "serde", serde(rename = "WAERMEPUMPE"))]
#[cfg_attr(feature = "strum", strum(serialize = "WAERMEPUMPE"))]
Waermepumpe,
#[cfg_attr(feature = "serde", serde(other, rename = "UNKNOWN"))]
#[cfg_attr(feature = "strum", strum(serialize = "UNKNOWN"))]
Unknown,
}
impl Kundentyp {
pub const VARIANTS: &'static [Self] = &[
Self::Gewerbe,
Self::Privat,
Self::Landwirt,
Self::Sonstige,
Self::Haushalt,
Self::Direktheizung,
Self::GemeinschaftMfh,
Self::Kirche,
Self::Kwk,
Self::Ladesaeule,
Self::BeleuchtungOeffentlich,
Self::BeleuchtungStrasse,
Self::Speicherheizung,
Self::UnterbrEinrichtung,
Self::Waermepumpe,
];
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::Gewerbe => "GEWERBE",
Self::Privat => "PRIVAT",
Self::Landwirt => "LANDWIRT",
Self::Sonstige => "SONSTIGE",
Self::Haushalt => "HAUSHALT",
Self::Direktheizung => "DIREKTHEIZUNG",
Self::GemeinschaftMfh => "GEMEINSCHAFT_MFH",
Self::Kirche => "KIRCHE",
Self::Kwk => "KWK",
Self::Ladesaeule => "LADESAEULE",
Self::BeleuchtungOeffentlich => "BELEUCHTUNG_OEFFENTLICH",
Self::BeleuchtungStrasse => "BELEUCHTUNG_STRASSE",
Self::Speicherheizung => "SPEICHERHEIZUNG",
Self::UnterbrEinrichtung => "UNTERBR_EINRICHTUNG",
Self::Waermepumpe => "WAERMEPUMPE",
Self::Unknown => "UNKNOWN",
}
}
pub fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
match s {
"GEWERBE" => Ok(Self::Gewerbe),
"PRIVAT" => Ok(Self::Privat),
"LANDWIRT" => Ok(Self::Landwirt),
"SONSTIGE" => Ok(Self::Sonstige),
"HAUSHALT" => Ok(Self::Haushalt),
"DIREKTHEIZUNG" => Ok(Self::Direktheizung),
"GEMEINSCHAFT_MFH" => Ok(Self::GemeinschaftMfh),
"KIRCHE" => Ok(Self::Kirche),
"KWK" => Ok(Self::Kwk),
"LADESAEULE" => Ok(Self::Ladesaeule),
"BELEUCHTUNG_OEFFENTLICH" => Ok(Self::BeleuchtungOeffentlich),
"BELEUCHTUNG_STRASSE" => Ok(Self::BeleuchtungStrasse),
"SPEICHERHEIZUNG" => Ok(Self::Speicherheizung),
"UNTERBR_EINRICHTUNG" => Ok(Self::UnterbrEinrichtung),
"WAERMEPUMPE" => Ok(Self::Waermepumpe),
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 Kundentyp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_wire())
}
}
impl AsRef<str> for Kundentyp {
fn as_ref(&self) -> &str {
self.as_wire()
}
}
#[cfg(feature = "versioned")]
impl crate::bo4e_enum_sealed::Sealed for Kundentyp {}
#[cfg(feature = "versioned")]
impl crate::Bo4eEnum for Kundentyp {
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 Kundentyp {
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 Kundentyp {
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 Kundentyp {
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 Kundentyp {
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 Kundentyp {
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()
}
}