// Communication & Notifications Domain // Contains Notification, Message, and communication models // Communication-specific Enums enum NotificationType { SYSTEM ANNOUNCEMENT ALERT REMINDER PROMOTION UPDATE WARNING INFO SUCCESS ERROR } enum NotificationCategory { GENERAL PROCUREMENT PAYMENT QUALITY WEATHER PRICE_ALERT TRAINING CERTIFICATION MAINTENANCE HARVEST PLANTING MARKET CONTRACT COMPLIANCE } enum NotificationStatus { PENDING SCHEDULED SENT DELIVERED FAILED CANCELLED EXPIRED } // Communication Models model Notification { id String @id @default(cuid()) title String message String type NotificationType category NotificationCategory @default(GENERAL) priority Priority @default(NORMAL) // Recipients recipientId String? // specific user ID recipientType UserRole? // or broadcast to user type recipientIds String[] // multiple specific users // Targeting farmerIds String[] // specific farmers buyerIds String[] // specific buyers region String? // geographic targeting productIds String[] // product-specific notifications // Content and media content String? // detailed content/body imageUrl String? actionUrl String? // deep link or action URL actionLabel String? // button text // Scheduling scheduledAt DateTime? // for scheduled notifications expiresAt DateTime? // expiration date // Status tracking status NotificationStatus @default(PENDING) sentAt DateTime? deliveredCount Int @default(0) readCount Int @default(0) clickCount Int @default(0) // Metadata source String? // system, admin, automated, etc. sourceId String? // reference to source entity tags String[] // for categorization metadata Json? // additional data // Tracking isRead Boolean @default(false) readAt DateTime? isClicked Boolean @default(false) clickedAt DateTime? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt // Relations recipients NotificationRecipient[] @@index([type]) @@index([category]) @@index([priority]) @@index([status]) @@index([scheduledAt]) @@index([recipientType]) @@index([region]) @@index([createdAt]) @@map("notifications") } model NotificationRecipient { id String @id @default(cuid()) notificationId String userId String isRead Boolean @default(false) readAt DateTime? isClicked Boolean @default(false) clickedAt DateTime? isDelivered Boolean @default(false) deliveredAt DateTime? createdAt DateTime @default(now()) // Relations notification Notification @relation(fields: [notificationId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@unique([notificationId, userId]) @@index([notificationId]) @@index([userId]) @@index([isRead]) @@index([isDelivered]) @@index([createdAt]) @@map("notification_recipients") } model Message { id String @id @default(cuid()) senderId String receiverId String? groupId String? subject String? content String messageType MessageType priority Priority @default(NORMAL) isRead Boolean @default(false) readAt DateTime? attachments String[] // file URLs deliveryStatus MessageStatus @default(SENT) sentAt DateTime @default(now()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([senderId]) @@index([receiverId]) @@index([messageType]) @@index([isRead]) @@index([sentAt]) @@index([deliveryStatus]) @@map("messages") }