// Code generated by oagen. DO NOT EDIT.

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

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CreateExperimentRequestNConsensus {
    V3,
    V5,
    V7,
    /// Wire value not recognized by this SDK version. The original
    /// integer is preserved verbatim. WorkOS may add new enum values
    /// server-side; matching on this variant lets callers handle
    /// forward-compatible values without panicking.
    Unknown(i64),
}

impl CreateExperimentRequestNConsensus {
    /// Canonical wire integer for this value. For [`Self::Unknown`] returns the
    /// original wire value as received from the API.
    #[allow(deprecated)]
    pub fn as_i64(&self) -> i64 {
        match self {
            Self::V3 => 3,
            Self::V5 => 5,
            Self::V7 => 7,
            Self::Unknown(n) => *n,
        }
    }
}

impl fmt::Display for CreateExperimentRequestNConsensus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.as_i64())
    }
}

impl From<i64> for CreateExperimentRequestNConsensus {
    #[allow(deprecated)]
    fn from(n: i64) -> Self {
        match n {
            3 => Self::V3,
            5 => Self::V5,
            7 => Self::V7,
            other => Self::Unknown(other),
        }
    }
}

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

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