use async_trait::async_trait;
use serde_json::Value;
#[async_trait]
pub trait Notification: Send + Sync {
fn subject(&self) -> String {
"Notification from Pakem".to_string()
}
fn to_mail(&self) -> Option<(String, Value)> {
None
}
fn to_database(&self) -> Option<Value> {
None
}
fn to_whatsapp(&self) -> Option<String> {
None
}
}
pub struct Notify;
impl Notify {
pub async fn send<N>(
req: &crate::core::request::Request,
to_email: &str,
notification: N,
) -> Result<(), String>
where
N: Notification,
{
if let Some((template, data)) = notification.to_mail() {
req.mail()
.to(to_email)
.subject(¬ification.subject())
.send(&template, data)
.await?;
}
Ok(())
}
}