import enum from datetime import datetime from sqlalchemy import Boolean, DateTime, Enum, ForeignKey, Integer, String, Text, func from sqlalchemy.orm import Mapped, mapped_column, relationship from app.database import Base class NotificationType(str, enum.Enum): INFO = "info" WARNING = "warning" SUCCESS = "success" PAYMENT = "payment" class Notification(Base): __tablename__ = "notifications" id: Mapped[int] = mapped_column(Integer, primary_key=True) user_id: Mapped[int] = mapped_column( Integer, ForeignKey("users.id"), nullable=False ) type: Mapped[NotificationType] = mapped_column( Enum(NotificationType, name="notification_type"), default=NotificationType.INFO ) title: Mapped[str] = mapped_column(String(128), nullable=False) text: Mapped[str] = mapped_column(Text, nullable=False) is_read: Mapped[bool] = mapped_column(Boolean, default=False) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now() ) user: Mapped["User"] = relationship(back_populates="notifications") def __repr__(self) -> str: return f""