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