use serde::{Deserialize, Serialize};
use std::fmt::Display;

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum DecisionListKind {
    #[serde(rename = "whitelist")]
    Allowlist,
    #[serde(rename = "blacklist")]
    Blocklist,
    #[serde(rename = "greylist")]
    Reviewlist,
}

impl DecisionListKind {
    pub fn name(&self) -> String {
        match self {
            DecisionListKind::Allowlist => "whitelist".to_string(),
            DecisionListKind::Blocklist => "blacklist".to_string(),
            DecisionListKind::Reviewlist => "greylist".to_string(),
        }
    }
}

impl Display for DecisionListKind {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.name())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_list_type_as_str() {
        assert_eq!(DecisionListKind::Blocklist.name(), "blacklist");
        assert_eq!(DecisionListKind::Allowlist.name(), "whitelist");
        assert_eq!(DecisionListKind::Reviewlist.name(), "greylist");
    }
}
