"""
Modèle SQLAlchemy pour les notifications MAESTRO
"""
from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, ForeignKey
from datetime import datetime
from app.database import Base


class Notification(Base):
    __tablename__ = "notifications"

    id = Column(Integer, primary_key=True, index=True)
    type = Column(String(50), nullable=False)  # alerte_stock, info, warning
    module = Column(String(50), nullable=False)  # etudes, fabrication, ressources
    titre = Column(String(255), nullable=False)
    message = Column(Text, nullable=True)
    projet_id = Column(Integer, ForeignKey("projets.id", ondelete="SET NULL"), nullable=True)
    lu = Column(Boolean, default=False)
    date_creation = Column(DateTime, default=datetime.utcnow)

    def __repr__(self):
        return f"<Notification {self.type} - {self.titre}>"