omni_orchestrator/schemas/v1/models/
notification.rs

1use serde::{Deserialize, Serialize};
2use chrono::{DateTime, NaiveDateTime, Utc};
3use serde_json::Value;
4use sqlx::Row;
5
6#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
7pub struct UserNotification {
8    pub id: i64,
9    pub user_id: i64,
10    pub org_id: Option<i64>,
11    pub app_id: Option<i64>,
12    pub notification_type: String,
13    pub message: String,
14    pub read_status: bool,
15    pub importance: String,
16    pub action_url: Option<String>,
17    pub action_label: Option<String>,
18    pub created_at: DateTime<Utc>,
19    pub expires_at: Option<DateTime<Utc>>,
20}
21
22// Role Notifications
23#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
24pub struct RoleNotification {
25    pub id: i64,
26    pub role_id: i64,
27    pub org_id: Option<i64>,
28    pub app_id: Option<i64>,
29    pub notification_type: String,
30    pub message: String,
31    pub importance: String,
32    pub action_url: Option<String>,
33    pub action_label: Option<String>,
34    pub created_at: DateTime<Utc>,
35    pub expires_at: Option<DateTime<Utc>>,
36}
37
38// Notification Acknowledgments
39#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
40pub struct NotificationAcknowledgment {
41    pub id: i64,
42    pub user_id: i64,
43    pub notification_id: Option<i64>,
44    pub role_notification_id: Option<i64>,
45    pub acknowledged_at: DateTime<Utc>
46}
47
48/// Represents a comprehensive view of a user's notifications with unread counts.
49/// This is useful for providing notification center overviews.
50#[derive(Debug, Serialize, Deserialize)]
51pub struct NotificationWithCount {
52    /// Direct notifications for the user
53    pub user_notifications: Vec<UserNotification>,
54    /// Role-based notifications applicable to the user
55    pub role_notifications: Vec<RoleNotification>,
56    /// User's acknowledgments of role notifications
57    pub acknowledgments: Vec<NotificationAcknowledgment>,
58    /// Count of unread direct user notifications
59    pub unread_user_count: i64,
60    /// Count of unacknowledged role notifications
61    pub unacknowledged_role_count: i64,
62    /// Total count of unread notifications (user + role)
63    pub total_unread_count: i64
64}
65
66/// Represents a user's notifications including those from their roles.
67/// This combines personal notifications with role-based ones.
68#[derive(Debug, Serialize, Deserialize)]
69pub struct UserNotificationWithRoleNotifications {
70    /// Direct notifications for the user
71    pub user_notifications: Vec<UserNotification>,
72    /// Role-based notifications applicable to the user
73    pub role_notifications: Vec<RoleNotification>,
74    /// User's acknowledgments of role notifications
75    pub acknowledgments: Vec<NotificationAcknowledgment>
76}
77
78#[derive(Debug, sqlx::FromRow, Serialize)]
79pub struct Notification {
80    pub id: i64,
81    pub user_id: Option<i64>,
82    pub org_id: Option<i64>,
83    pub app_id: Option<i64>,
84    pub notification_type: String, // enum: 'info', 'warning', 'error', 'success'
85    pub message: String,
86    pub read_status: bool,
87    pub created_at: DateTime<Utc>,
88}