this repo has no description
1use chrono::{DateTime, Utc}; 2use serde::{Deserialize, Serialize}; 3use sqlx::FromRow; 4use uuid::Uuid; 5 6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, sqlx::Type, Serialize, Deserialize)] 7#[sqlx(type_name = "comms_channel", rename_all = "lowercase")] 8pub enum CommsChannel { 9 Email, 10 Discord, 11 Telegram, 12 Signal, 13} 14 15#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, Serialize, Deserialize)] 16#[sqlx(type_name = "comms_status", rename_all = "lowercase")] 17pub enum CommsStatus { 18 Pending, 19 Processing, 20 Sent, 21 Failed, 22} 23 24#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, Serialize, Deserialize)] 25#[sqlx(type_name = "comms_type", rename_all = "snake_case")] 26pub enum CommsType { 27 Welcome, 28 EmailVerification, 29 PasswordReset, 30 EmailUpdate, 31 AccountDeletion, 32 AdminEmail, 33 PlcOperation, 34 TwoFactorCode, 35 PasskeyRecovery, 36 LegacyLoginAlert, 37} 38 39#[derive(Debug, Clone, FromRow)] 40pub struct QueuedComms { 41 pub id: Uuid, 42 pub user_id: Uuid, 43 pub channel: CommsChannel, 44 pub comms_type: CommsType, 45 pub status: CommsStatus, 46 pub recipient: String, 47 pub subject: Option<String>, 48 pub body: String, 49 pub metadata: Option<serde_json::Value>, 50 pub attempts: i32, 51 pub max_attempts: i32, 52 pub last_error: Option<String>, 53 pub created_at: DateTime<Utc>, 54 pub updated_at: DateTime<Utc>, 55 pub scheduled_for: DateTime<Utc>, 56 pub processed_at: Option<DateTime<Utc>>, 57} 58 59pub struct NewComms { 60 pub user_id: Uuid, 61 pub channel: CommsChannel, 62 pub comms_type: CommsType, 63 pub recipient: String, 64 pub subject: Option<String>, 65 pub body: String, 66 pub metadata: Option<serde_json::Value>, 67} 68 69impl NewComms { 70 pub fn new( 71 user_id: Uuid, 72 channel: CommsChannel, 73 comms_type: CommsType, 74 recipient: String, 75 subject: Option<String>, 76 body: String, 77 ) -> Self { 78 Self { 79 user_id, 80 channel, 81 comms_type, 82 recipient, 83 subject, 84 body, 85 metadata: None, 86 } 87 } 88 89 pub fn email( 90 user_id: Uuid, 91 comms_type: CommsType, 92 recipient: String, 93 subject: String, 94 body: String, 95 ) -> Self { 96 Self::new( 97 user_id, 98 CommsChannel::Email, 99 comms_type, 100 recipient, 101 Some(subject), 102 body, 103 ) 104 } 105}