use config::AppConfig; use queue::NatsProducer; use crate::EmailMessage; #[derive(Clone)] pub struct AppEmail { producer: NatsProducer, topic: String, } impl AppEmail { pub async fn init(config: &AppConfig) -> anyhow::Result { Ok(Self { producer: NatsProducer::new(config).await?, topic: config.email_topic(), }) } pub fn set_metrics(&mut self, registry: track::MetricsRegistry) { self.producer.set_metrics(registry); } pub fn with_topic( producer: NatsProducer, topic: impl Into, ) -> Self { Self { producer, topic: topic.into(), } } pub async fn send(&self, message: EmailMessage) -> anyhow::Result<()> { self.producer .send(&self.topic, &message.to, &message, None) .await } pub fn topic(&self) -> &str { &self.topic } }