from sqlalchemy import String, Text, Integer, Boolean, ForeignKey, func from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.orm import Mapped, mapped_column from datetime import datetime from typing import Optional from app.database import Base class Notification(Base): __tablename__ = "notifications" id: Mapped[int] = mapped_column(primary_key=True, index=True) user_id: Mapped[int] = mapped_column( Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False ) type: Mapped[str] = mapped_column(String(50), nullable=False) title: Mapped[Optional[str]] = mapped_column(String(255), nullable=True) message: Mapped[Optional[str]] = mapped_column(Text, nullable=True) data: Mapped[Optional[dict]] = mapped_column(JSONB, nullable=True) source_type: Mapped[Optional[str]] = mapped_column(String(50), nullable=True) source_id: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) is_read: Mapped[bool] = mapped_column(Boolean, default=False, server_default="false") created_at: Mapped[datetime] = mapped_column(default=func.now(), server_default=func.now())