from django.db import models
from django.conf import settings


NOTIFICATION_TYPES = [
    ("message",          "New Message"),
    ("friend_request",   "Friend Request"),
    ("friend_accepted",  "Friend Accepted"),
    ("post_comment",     "Post Comment"),
    ("post_reaction",    "Post Reaction"),
    ("announcement",     "Announcement"),
    ("room_join",        "Room Join"),
    ("biashara_message", "Biashara Message"),
    ("system",           "System"),
]


class Notification(models.Model):
    recipient   = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name="notifications"
    )
    sender      = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET_NULL,
        null=True, blank=True,
        related_name="sent_notifications"
    )
    notif_type  = models.CharField(max_length=30, choices=NOTIFICATION_TYPES)
    title       = models.CharField(max_length=200)
    body        = models.TextField(blank=True)
    link        = models.CharField(max_length=300, blank=True)
    is_read     = models.BooleanField(default=False)
    created_at  = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ["-created_at"]

    def __str__(self):
        return f"{self.recipient.username} — {self.notif_type}: {self.title}"