from django.db import models
from Auth.models import Profile

class Messagerie(models.Model):
    id = models.AutoField(primary_key=True)
    objet = models.CharField(max_length=200, default="", blank=True)
    emetteur = models.ForeignKey(Profile, on_delete=models.PROTECT, related_name='messages_envoyes')
    destinataire = models.ForeignKey(Profile, on_delete=models.PROTECT, related_name='messages_recus')
    corpus = models.CharField(max_length=200, default="", blank=True)
    date_envoi = models.DateTimeField(auto_now_add=True)  # Date d'envoi du message
    is_read = models.BooleanField(default=False)  # Statut lu/non lu
    conversation_id = models.CharField(max_length=100, blank=True, default="")  # Pour regrouper les messages par conversation

    def __str__(self):
        return f'Messagerie_{self.id}'