use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
Completed,
Voided,
Review,
Disputing,
Unknown(String),
}
impl SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
#[allow(deprecated)]
pub fn as_str(&self) -> &str {
match self {
Self::Completed => "COMPLETED",
Self::Voided => "VOIDED",
Self::Review => "REVIEW",
Self::Disputing => "DISPUTING",
Self::Unknown(s) => s.as_str(),
}
}
pub fn is_known(&self) -> bool {
!matches!(self, Self::Unknown(_))
}
}
impl fmt::Display for SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl AsRef<str> for SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl FromStr for SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
type Err = std::convert::Infallible;
#[allow(deprecated)]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"COMPLETED" => Self::Completed,
"VOIDED" => Self::Voided,
"REVIEW" => Self::Review,
"DISPUTING" => Self::Disputing,
other => Self::Unknown(other.to_string()),
})
}
}
impl From<String> for SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
fn from(s: String) -> Self {
match Self::from_str(&s) {
Ok(Self::Unknown(_)) => Self::Unknown(s),
Ok(other) => other,
}
}
}
impl From<&str> for SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
fn from(s: &str) -> Self {
Self::from_str(s).unwrap_or_else(|_| Self::Unknown(s.to_string()))
}
}
impl Serialize for SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_str(self.as_str())
}
}
impl<'de> Deserialize<'de> for SdkUpdateInvoiceStatusRequestApplicationJsonStatus {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}