#[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 Wiederholungstyp {
#[cfg_attr(feature = "serde", serde(rename = "TAEGLICH"))]
#[cfg_attr(feature = "strum", strum(serialize = "TAEGLICH"))]
Taeglich,
#[cfg_attr(feature = "serde", serde(rename = "WERKTAGS"))]
#[cfg_attr(feature = "strum", strum(serialize = "WERKTAGS"))]
Werktags,
#[cfg_attr(feature = "serde", serde(rename = "WOCHENENDE"))]
#[cfg_attr(feature = "strum", strum(serialize = "WOCHENENDE"))]
Wochenende,
#[cfg_attr(feature = "serde", serde(rename = "FEIERTAGS"))]
#[cfg_attr(feature = "strum", strum(serialize = "FEIERTAGS"))]
Feiertags,
#[cfg_attr(feature = "serde", serde(rename = "MONTAGS"))]
#[cfg_attr(feature = "strum", strum(serialize = "MONTAGS"))]
Montags,
#[cfg_attr(feature = "serde", serde(rename = "DIENSTAGS"))]
#[cfg_attr(feature = "strum", strum(serialize = "DIENSTAGS"))]
Dienstags,
#[cfg_attr(feature = "serde", serde(rename = "MITTWOCHS"))]
#[cfg_attr(feature = "strum", strum(serialize = "MITTWOCHS"))]
Mittwochs,
#[cfg_attr(feature = "serde", serde(rename = "DONNERSTAGS"))]
#[cfg_attr(feature = "strum", strum(serialize = "DONNERSTAGS"))]
Donnerstags,
#[cfg_attr(feature = "serde", serde(rename = "FREITAGS"))]
#[cfg_attr(feature = "strum", strum(serialize = "FREITAGS"))]
Freitags,
#[cfg_attr(feature = "serde", serde(rename = "SAMSTAGS"))]
#[cfg_attr(feature = "strum", strum(serialize = "SAMSTAGS"))]
Samstags,
#[cfg_attr(feature = "serde", serde(rename = "SONNTAGS"))]
#[cfg_attr(feature = "strum", strum(serialize = "SONNTAGS"))]
Sonntags,
#[cfg_attr(feature = "serde", serde(other, rename = "UNKNOWN"))]
#[cfg_attr(feature = "strum", strum(serialize = "UNKNOWN"))]
Unknown,
}
impl Wiederholungstyp {
pub const VARIANTS: &'static [Self] = &[
Self::Taeglich,
Self::Werktags,
Self::Wochenende,
Self::Feiertags,
Self::Montags,
Self::Dienstags,
Self::Mittwochs,
Self::Donnerstags,
Self::Freitags,
Self::Samstags,
Self::Sonntags,
];
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::Taeglich => "TAEGLICH",
Self::Werktags => "WERKTAGS",
Self::Wochenende => "WOCHENENDE",
Self::Feiertags => "FEIERTAGS",
Self::Montags => "MONTAGS",
Self::Dienstags => "DIENSTAGS",
Self::Mittwochs => "MITTWOCHS",
Self::Donnerstags => "DONNERSTAGS",
Self::Freitags => "FREITAGS",
Self::Samstags => "SAMSTAGS",
Self::Sonntags => "SONNTAGS",
Self::Unknown => "UNKNOWN",
}
}
pub fn from_wire(s: &str) -> Result<Self, crate::error::UnknownVariant> {
match s {
"TAEGLICH" => Ok(Self::Taeglich),
"WERKTAGS" => Ok(Self::Werktags),
"WOCHENENDE" => Ok(Self::Wochenende),
"FEIERTAGS" => Ok(Self::Feiertags),
"MONTAGS" => Ok(Self::Montags),
"DIENSTAGS" => Ok(Self::Dienstags),
"MITTWOCHS" => Ok(Self::Mittwochs),
"DONNERSTAGS" => Ok(Self::Donnerstags),
"FREITAGS" => Ok(Self::Freitags),
"SAMSTAGS" => Ok(Self::Samstags),
"SONNTAGS" => Ok(Self::Sonntags),
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 Wiederholungstyp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_wire())
}
}
impl AsRef<str> for Wiederholungstyp {
fn as_ref(&self) -> &str {
self.as_wire()
}
}
#[cfg(feature = "versioned")]
impl crate::bo4e_enum_sealed::Sealed for Wiederholungstyp {}
#[cfg(feature = "versioned")]
impl crate::Bo4eEnum for Wiederholungstyp {
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 Wiederholungstyp {
fn collect_unknown_enums(&self, path: &str, out: &mut Vec<String>) {
if self.is_unknown() {
out.push(path.to_owned());
}
}
}
#[cfg(all(feature = "sqlx", feature = "json"))]
impl sqlx::Type<sqlx::Postgres> for Wiederholungstyp {
fn type_info() -> sqlx::postgres::PgTypeInfo {
<String as sqlx::Type<sqlx::Postgres>>::type_info()
}
}
#[cfg(all(feature = "sqlx", feature = "json"))]
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Wiederholungstyp {
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(all(feature = "sqlx", feature = "json"))]
impl<'r> sqlx::Decode<'r, sqlx::Postgres> for Wiederholungstyp {
fn decode(
value: <sqlx::Postgres as sqlx::Database>::ValueRef<'r>,
) -> Result<Self, sqlx::error::BoxDynError> {
let s = <String as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
serde_json::from_value(serde_json::Value::String(s))
.map_err(|e| Box::new(e) as sqlx::error::BoxDynError)
}
}
#[cfg(test)]
impl proptest::arbitrary::Arbitrary for Wiederholungstyp {
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()
}
}