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


class Notification(models.Model):
    TYPE_CHOICES = [
        ('lead_created', 'Lead Created'),
        ('lead_updated', 'Lead Updated'),
        ('approval_action', 'Approval Action'),
        ('task_assigned', 'Task Assigned'),
        ('task_due', 'Task Due Soon'),
        ('mention', '@Mention'),
        ('comment', 'New Comment'),
        ('invoice', 'Invoice Update'),
        ('project_stage', 'Project Stage Changed'),
        ('meeting', 'New Meeting'),
        ('expense', 'Expense Update'),
        ('general', 'General'),
    ]

    user = models.ForeignKey(
        settings.AUTH_USER_MODEL, on_delete=models.CASCADE,
        related_name='notifications'
    )
    type = models.CharField(max_length=20, choices=TYPE_CHOICES, default='general')
    title = models.CharField(max_length=255)
    message = models.TextField()
    link = models.CharField(max_length=500, blank=True, help_text='Relative path to navigate')
    is_read = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        app_label = 'notifications'
        ordering = ['-created_at']

    def __str__(self):
        return f'{self.title} → {self.user.full_name}'
