use serde::{Deserialize, Serialize};

pub mod mastodon;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Domain {
    pub domain: String,
    pub level: Level,
    pub notes: Option<String>,
    pub reason: Option<String>,
    pub source: Option<String>,
}

impl Domain {
    pub fn key(&self) -> String {
        format!(
            "{}:{}",
            self.domain,
            self.source.to_owned().unwrap_or_default()
        )
    }
}

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

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct List {
    pub domains: Vec<Domain>,
}

impl From<Vec<Domain>> for List {
    fn from(domains: Vec<Domain>) -> Self {
        Self { domains }
    }
}

impl List {
    pub fn empty() -> Self {
        Self { domains: vec![] }
    }

    pub fn merge(&mut self, mut other: List) {
        self.domains.append(&mut other.domains);
    }
}

#[derive(Debug, Deserialize)]
pub struct Search {
    pub threshold: Option<usize>,
    pub domain: Option<String>,
}
