from django.db import models from apps.core.models import TimeStampedModel, UUIDModel class NotificationTemplate(UUIDModel, TimeStampedModel): class Channel(models.TextChoices): SMS = "sms", "SMS" EMAIL = "email", "Email" PUSH = "push", "Push" INAPP = "inapp", "In-app" event = models.CharField(max_length=120, db_index=True) channel = models.CharField(max_length=12, choices=Channel.choices, default=Channel.SMS) subject = models.CharField(max_length=255, blank=True) body = models.TextField(help_text="Supports {{variable}} placeholders.") enabled = models.BooleanField(default=True) def __str__(self) -> str: return f"{self.event} ({self.channel})" class NotificationRule(UUIDModel, TimeStampedModel): event = models.CharField(max_length=120, db_index=True) template = models.ForeignKey(NotificationTemplate, on_delete=models.CASCADE, related_name="rules") recipients = models.JSONField(default=list, blank=True) enabled = models.BooleanField(default=True) class NotificationLog(UUIDModel, TimeStampedModel): template = models.ForeignKey(NotificationTemplate, null=True, blank=True, on_delete=models.SET_NULL) recipient = models.CharField(max_length=200, blank=True) channel = models.CharField(max_length=12) status = models.CharField(max_length=20, default="pending") error = models.TextField(blank=True) sent_at = models.DateTimeField(null=True, blank=True)