use anyhow::Result;
use serde::{Deserialize, Serialize};
use serde_json::from_str;

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Rights {
    #[serde(rename = "Super-User")]
    SuperUser,

    #[serde(rename = "PTS-User")]
    PTSUser,

    #[serde(rename = "Premium-User")]
    PremiumUser,

    #[serde(rename = "Standard-User")]
    StandardUser,

    #[serde(rename = "Test-User")]
    TestUser,
}

impl TryFrom<String> for Rights {
    type Error = anyhow::Error;

    fn try_from(value: String) -> Result<Self> {
        Ok(from_str(&value)?)
    }
}

impl Into<mysql::Value> for Rights {
    fn into(self) -> mysql::Value {
        serde_json::to_string(&self).unwrap().into()
    }
}
