use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use sqlx::FromRow; use uuid::Uuid; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, sqlx::Type, Serialize, Deserialize)] #[sqlx(type_name = "notification_channel", rename_all = "lowercase")] pub enum NotificationChannel { Email, Discord, Telegram, Signal, } #[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, Serialize, Deserialize)] #[sqlx(type_name = "notification_status", rename_all = "lowercase")] pub enum NotificationStatus { Pending, Processing, Sent, Failed, } #[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, Serialize, Deserialize)] #[sqlx(type_name = "notification_type", rename_all = "snake_case")] pub enum NotificationType { Welcome, EmailVerification, PasswordReset, EmailUpdate, AccountDeletion, AdminEmail, PlcOperation, TwoFactorCode, } #[derive(Debug, Clone, FromRow)] pub struct QueuedNotification { pub id: Uuid, pub user_id: Uuid, pub channel: NotificationChannel, pub notification_type: NotificationType, pub status: NotificationStatus, pub recipient: String, pub subject: Option, pub body: String, pub metadata: Option, pub attempts: i32, pub max_attempts: i32, pub last_error: Option, pub created_at: DateTime, pub updated_at: DateTime, pub scheduled_for: DateTime, pub processed_at: Option>, } pub struct NewNotification { pub user_id: Uuid, pub channel: NotificationChannel, pub notification_type: NotificationType, pub recipient: String, pub subject: Option, pub body: String, pub metadata: Option, } impl NewNotification { pub fn new( user_id: Uuid, channel: NotificationChannel, notification_type: NotificationType, recipient: String, subject: Option, body: String, ) -> Self { Self { user_id, channel, notification_type, recipient, subject, body, metadata: None, } } pub fn email( user_id: Uuid, notification_type: NotificationType, recipient: String, subject: String, body: String, ) -> Self { Self::new( user_id, NotificationChannel::Email, notification_type, recipient, Some(subject), body, ) } }