1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use serde::{Deserialize,Serialize,Deserializer};

#[derive(Eq, PartialEq, Clone, Serialize, Debug, Deserialize)]
pub enum TotpMode {
  Mandatory,
  Optional,
  No,
}
impl Default for TotpMode {
    fn default() -> Self {
       TotpMode::No
    }
}
impl std::fmt::Display for TotpMode {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            TotpMode::Mandatory => write!(f,"mandatory"),
            TotpMode::Optional => write!(f,"optional"),
            TotpMode::No => write!(f,"no"),
        }
    }
}
impl TotpMode {
    pub fn from_str(value: &str) -> TotpMode {
        match value {
            "mandatory" | "Mandaltory" | "required" | "Required"  => TotpMode::Mandatory,
            "optional" |  "Optional" => TotpMode::Optional,
            "no" |  "No" => TotpMode::No,
            _ => TotpMode::default(),
        }
    }
}
pub fn deserialize_totp_mode<'de, D>(deserializer: D) -> Result<TotpMode, D::Error>
where D: Deserializer<'de> {
    let buf = String::deserialize(deserializer)?;
    Ok(TotpMode::from_str(&buf))
}