// 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 StepArtifactRefOperation {
    Extraction,
    Split,
    Classification,
    Parse,
    Edit,
    Partition,
    ConditionalEvaluation,
    ReviewTriggerEvaluation,
    WhileLoopTermination,
    ApiCallInvocation,
    FunctionInvocation,
    /// 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 StepArtifactRefOperation {
    /// 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::Extraction => "extraction",
            Self::Split => "split",
            Self::Classification => "classification",
            Self::Parse => "parse",
            Self::Edit => "edit",
            Self::Partition => "partition",
            Self::ConditionalEvaluation => "conditional_evaluation",
            Self::ReviewTriggerEvaluation => "review_trigger_evaluation",
            Self::WhileLoopTermination => "while_loop_termination",
            Self::ApiCallInvocation => "api_call_invocation",
            Self::FunctionInvocation => "function_invocation",
            Self::Unknown(s) => s.as_str(),
        }
    }
}

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

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

impl FromStr for StepArtifactRefOperation {
    type Err = std::convert::Infallible;
    #[allow(deprecated)]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "extraction" => Self::Extraction,
            "split" => Self::Split,
            "classification" => Self::Classification,
            "parse" => Self::Parse,
            "edit" => Self::Edit,
            "partition" => Self::Partition,
            "conditional_evaluation" => Self::ConditionalEvaluation,
            "review_trigger_evaluation" => Self::ReviewTriggerEvaluation,
            "while_loop_termination" => Self::WhileLoopTermination,
            "api_call_invocation" => Self::ApiCallInvocation,
            "function_invocation" => Self::FunctionInvocation,
            other => Self::Unknown(other.to_string()),
        })
    }
}

impl From<String> for StepArtifactRefOperation {
    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 StepArtifactRefOperation {
    fn from(s: &str) -> Self {
        Self::from_str(s).unwrap_or_else(|_| Self::Unknown(s.to_string()))
    }
}

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

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