use std::str::FromStr;
use crate::error::AppError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Role {
Admin,
SuperAdmin,
Worker,
}
impl Role {
pub fn as_auth0_name(&self) -> &str {
match self {
Role::Admin => "ADMIN",
Role::SuperAdmin => "SUPER_ADMIN",
Role::Worker => "WORKER",
}
}
}
impl FromStr for Role {
type Err = AppError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"admin" => Ok(Role::Admin),
"super_admin" => Ok(Role::SuperAdmin),
"worker" => Ok(Role::Worker),
_ => Err(AppError::InvalidRole(s.to_string())),
}
}
}