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