use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Debug, Validate, Serialize, Deserialize, Clone, PartialEq)]
#[serde(transparent)]
pub struct CustomString {
#[validate(length(max = 20, message = "String length must not exceed 20 characters"))]
pub value: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ChargingLimitSourceEnumType {
#[serde(rename_all = "UPPERCASE")]
Standard(StandardChargingLimitSourceEnumType),
Custom(CustomString),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum StandardChargingLimitSourceEnumType {
#[serde(rename = "EMS")]
EMS,
#[serde(rename = "Other")]
Other,
#[serde(rename = "SO")]
SO,
#[serde(rename = "CSO")]
CSO,
}
impl ChargingLimitSourceEnumType {
pub fn as_str(&self) -> &str {
match self {
Self::Standard(s) => match s {
StandardChargingLimitSourceEnumType::EMS => "EMS",
StandardChargingLimitSourceEnumType::Other => "Other",
StandardChargingLimitSourceEnumType::SO => "SO",
StandardChargingLimitSourceEnumType::CSO => "CSO",
},
Self::Custom(s) => &s.value,
}
}
}
impl From<String> for ChargingLimitSourceEnumType {
fn from(s: String) -> Self {
match s.as_str() {
"EMS" => Self::Standard(StandardChargingLimitSourceEnumType::EMS),
"Other" => Self::Standard(StandardChargingLimitSourceEnumType::Other),
"SO" => Self::Standard(StandardChargingLimitSourceEnumType::SO),
"CSO" => Self::Standard(StandardChargingLimitSourceEnumType::CSO),
_ => Self::Custom(CustomString { value: s }),
}
}
}
impl ToString for ChargingLimitSourceEnumType {
fn to_string(&self) -> String {
self.as_str().to_string()
}
}