use laravel::mail::Address;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Recipient {
pub email: String,
#[serde(default)]
pub name: Option<String>,
#[serde(default)]
pub locale: Option<String>,
}
impl Recipient {
#[must_use]
pub fn new(email: impl Into<String>) -> Self {
Self {
email: email.into(),
name: None,
locale: None,
}
}
#[must_use]
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
#[must_use]
pub fn locale(mut self, locale: impl Into<String>) -> Self {
self.locale = Some(locale.into());
self
}
pub(crate) fn address(&self) -> Address {
let address = Address::new(self.email.clone());
match &self.name {
Some(name) => address.with_name(name.clone()),
None => address,
}
}
}
impl From<&str> for Recipient {
fn from(email: &str) -> Self {
Self::new(email)
}
}
impl From<String> for Recipient {
fn from(email: String) -> Self {
Self::new(email)
}
}