backbone-mailing 0.4.0

Email marketing — mass-mail engine: audiences, subscriptions, hand-set mailing lifecycle, seeded A/B testing, per-recipient traces, cycle-44 bridge targets (Odoo mass_mailing port)
use serde::{Deserialize, Serialize};
use sqlx::Type;
use std::str::FromStr;
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "snake_case")]
#[sqlx(type_name = "mailing_target_model", rename_all = "snake_case")]
pub enum MailingTargetModel {
    MailingContact,
    Party,
    CrmLead,
    CrmDeal,
    SellingCustomer,
    EventRegistration,
}

impl std::fmt::Display for MailingTargetModel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::MailingContact => write!(f, "mailing_contact"),
            Self::Party => write!(f, "party"),
            Self::CrmLead => write!(f, "crm_lead"),
            Self::CrmDeal => write!(f, "crm_deal"),
            Self::SellingCustomer => write!(f, "selling_customer"),
            Self::EventRegistration => write!(f, "event_registration"),
        }
    }
}

impl FromStr for MailingTargetModel {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "mailing_contact" => Ok(Self::MailingContact),
            "party" => Ok(Self::Party),
            "crm_lead" => Ok(Self::CrmLead),
            "crm_deal" => Ok(Self::CrmDeal),
            "selling_customer" => Ok(Self::SellingCustomer),
            "event_registration" => Ok(Self::EventRegistration),
            _ => Err(format!("Unknown MailingTargetModel variant: {}", s)),
        }
    }
}

impl Default for MailingTargetModel {
    fn default() -> Self {
        Self::MailingContact
    }
}