// Code generated by oagen. DO NOT EDIT.

use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum WorkflowTableFilterOperator {
    Eq,
    Ne,
    Gt,
    Gte,
    Lt,
    Lte,
    Contains,
    NotContains,
    StartsWith,
    EndsWith,
    In,
    NotIn,
    Between,
    IsEmpty,
    IsNotEmpty,
    IsNull,
    IsNotNull,
    /// Wire value not recognized by this SDK version. The original
    /// string is preserved verbatim. WorkOS may add new enum values
    /// server-side; matching on this variant lets callers handle
    /// forward-compatible values without panicking.
    Unknown(String),
}

impl WorkflowTableFilterOperator {
    /// Canonical wire string for this value. For [`Self::Unknown`] returns the
    /// original wire value as received from the API.
    #[allow(deprecated)]
    pub fn as_str(&self) -> &str {
        match self {
            Self::Eq => "eq",
            Self::Ne => "ne",
            Self::Gt => "gt",
            Self::Gte => "gte",
            Self::Lt => "lt",
            Self::Lte => "lte",
            Self::Contains => "contains",
            Self::NotContains => "not_contains",
            Self::StartsWith => "starts_with",
            Self::EndsWith => "ends_with",
            Self::In => "in",
            Self::NotIn => "not_in",
            Self::Between => "between",
            Self::IsEmpty => "is_empty",
            Self::IsNotEmpty => "is_not_empty",
            Self::IsNull => "is_null",
            Self::IsNotNull => "is_not_null",
            Self::Unknown(s) => s.as_str(),
        }
    }
}

impl fmt::Display for WorkflowTableFilterOperator {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

impl AsRef<str> for WorkflowTableFilterOperator {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl FromStr for WorkflowTableFilterOperator {
    type Err = std::convert::Infallible;
    #[allow(deprecated)]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "eq" => Self::Eq,
            "ne" => Self::Ne,
            "gt" => Self::Gt,
            "gte" => Self::Gte,
            "lt" => Self::Lt,
            "lte" => Self::Lte,
            "contains" => Self::Contains,
            "not_contains" => Self::NotContains,
            "starts_with" => Self::StartsWith,
            "ends_with" => Self::EndsWith,
            "in" => Self::In,
            "not_in" => Self::NotIn,
            "between" => Self::Between,
            "is_empty" => Self::IsEmpty,
            "is_not_empty" => Self::IsNotEmpty,
            "is_null" => Self::IsNull,
            "is_not_null" => Self::IsNotNull,
            other => Self::Unknown(other.to_string()),
        })
    }
}

impl From<String> for WorkflowTableFilterOperator {
    fn from(s: String) -> Self {
        // Reuse the original `String` allocation in the fallback branch.
        match Self::from_str(&s) {
            Ok(Self::Unknown(_)) => Self::Unknown(s),
            Ok(other) => other,
        }
    }
}

impl From<&str> for WorkflowTableFilterOperator {
    fn from(s: &str) -> Self {
        Self::from_str(s).unwrap_or_else(|_| Self::Unknown(s.to_string()))
    }
}

impl Serialize for WorkflowTableFilterOperator {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for WorkflowTableFilterOperator {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}
