zedazo-core 0.5.1

Núcleo de dominio y casos de uso de Zedazo (sin CLI/HTTP)
Documentation
//! Entidad canónica de dominio y value objects.
//!
//! `Contact` es la representación limpia de un contacto,
//! sin escapes RFC ni datos binarios.

use std::collections::HashSet;

/// Entidad canónica de dominio.
#[derive(Debug, Clone)]
pub struct Contact {
    pub uid: String,
    pub fn_value: String,
    pub structured_name: Option<StructuredName>,
    pub org: Option<String>,
    pub org_fullname: Option<String>,
    pub org_legal_form: Option<String>,
    pub emails: Vec<TypedValue>,
    pub tels: Vec<Tel>,
    pub title: Option<String>,
    pub role: Option<String>,
    pub note: Option<String>,
    pub addresses: Vec<Address>,
    pub categories: CategorySet,
    pub source_detail: SourceDetail,
    pub decision: super::screening::ScreeningDecision,
    pub screening_rule: String,
    pub merged_uids: Vec<String>,
    /// Campo ADR: decisión manual de rescate/cuarentena (ADR-XXXX).
    /// Formato: "ADR-XXXX:motivo" o vacío si no hay decisión manual.
    pub adr_field: Option<String>,
}

/// Componentes estructurados del nombre (RFC 6350).
#[derive(Debug, Clone, Default)]
pub struct StructuredName {
    pub family: Vec<String>,
    pub given: Vec<String>,
    pub additional: Vec<String>,
    pub prefix: Vec<String>,
    pub suffix: Vec<String>,
}

/// Número de teléfono normalizado.
#[derive(Debug, Clone)]
pub struct Tel {
    pub value: String,
    pub tel_type: TelType,
    pub normalized: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TelType {
    Cell,
    Home,
    Work,
    Main,
    Fax,
    Pager,
    Text,
    Video,
    Other,
}

/// Dirección postal (RFC 6350 ADR).
#[derive(Debug, Clone, Default)]
pub struct Address {
    pub po_box: String,
    pub extended: String,
    pub street: String,
    pub locality: String,
    pub region: String,
    pub postal_code: String,
    pub country: String,
    pub types: Vec<String>,
}

/// Valor con tipos y preferencia (EMAIL, TEL sin normalizar).
#[derive(Debug, Clone)]
pub struct TypedValue {
    pub value: String,
    pub types: Vec<String>,
    pub pref: u8,
}

/// Conjunto de categorías N1, N2, N3.
#[derive(Debug, Clone, Default)]
pub struct CategorySet {
    pub n1: HashSet<String>,
    pub n2: HashSet<String>,
    pub n3: Vec<String>,
    /// Campo ADR: decisiones manuales de rescate/cuarentena (ADR-XXXX).
    /// Formato: "ADR-XXXX:motivo" o vacío si no hay decisión manual.
    pub adr_field: Option<String>,
}

impl CategorySet {
    pub fn has_n1(&self) -> bool {
        !self.n1.is_empty()
    }
}

/// Origen detallado del contacto.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SourceDetail {
    ProtonAutosave,
    ProtonImport,
    ProtonWeb,
    Google,
    Apple,
    Unknown(String),
}