use serde::{Deserialize, Serialize};
use sqlx::Type;
use std::str::FromStr;
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "snake_case")]
#[sqlx(type_name = "request_priority", rename_all = "snake_case")]
pub enum RequestPriority {
VeryLow,
Low,
Normal,
High,
}
impl std::fmt::Display for RequestPriority {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::VeryLow => write!(f, "very_low"),
Self::Low => write!(f, "low"),
Self::Normal => write!(f, "normal"),
Self::High => write!(f, "high"),
}
}
}
impl FromStr for RequestPriority {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"very_low" => Ok(Self::VeryLow),
"low" => Ok(Self::Low),
"normal" => Ok(Self::Normal),
"high" => Ok(Self::High),
_ => Err(format!("Unknown RequestPriority variant: {}", s)),
}
}
}
impl Default for RequestPriority {
fn default() -> Self {
Self::Low
}
}