felicia 0.5.1

service for accessing and sharing lists of bad actors
Documentation
use std::fmt::Display;

use serde::{Deserialize, Serialize};

use super::Domain;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MastodonEntry {
    pub domain: String,
    pub severity: Level,
    pub public_comment: String,
    pub reject_media: bool,
    pub reject_reports: bool,
    pub obfuscate: bool,
}

impl MastodonEntry {
    pub fn as_csv_entry(&self) -> String {
        format!(
            "{},{},\"{}\",FALSE,FALSE,FALSE",
            self.domain, self.severity, self.public_comment
        )
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Level {
    Silence,
    Block,
}

impl Display for Level {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Level::Silence => write!(f, "silence"),
            Level::Block => write!(f, "block"),
        }
    }
}

impl From<super::Level> for Level {
    fn from(value: super::Level) -> Self {
        match value {
            super::Level::Low => Self::Silence,
            super::Level::Medium => Self::Block,
            super::Level::Severe => Self::Block,
        }
    }
}

impl From<Domain> for MastodonEntry {
    fn from(value: Domain) -> Self {
        Self {
            domain: value.domain,
            severity: value.level.into(),
            public_comment: value.reason.unwrap_or_default(),
            reject_media: false,
            reject_reports: false,
            obfuscate: false,
        }
    }
}