"""Platform notifications (APPS_PLATFORM ยง10, plan step 1.11). System messages to staff: license limits and expiry, support access used, print failures (later: Ergani, close-day reminders). NOT staff chat or manager messages (models/message.py, F-030), which stay separate. - The text is an i18n key (`notification.` in core/i18n/*.json) + params, rendered in the reader's language when listed. - audience: "all_managers" (holders of core.dashboard.access) | "perm:" | "user:". - dedupe_key: while a row with the same key is still live (expires_at NULL or future), notify() bumps its `count` / `last_at` instead of adding a row. Written through core/notifications.py only. """ from sqlalchemy import JSON, Column, ForeignKey, Integer, String from core.timeutil import UTCDateTime, utcnow from database import Base class Notification(Base): __tablename__ = "notifications" __table_args__ = {"sqlite_autoincrement": True} id = Column(Integer, primary_key=True, autoincrement=True) key = Column(String, nullable=False, index=True) # e.g. "license.limit_reached" severity = Column(String, nullable=False, default="info") # info | warning | critical audience = Column(String, nullable=False, index=True) params = Column(JSON, nullable=True) dedupe_key = Column(String, nullable=True, index=True) count = Column(Integer, nullable=False, default=1) # occurrences folded in by dedupe created_at = Column(UTCDateTime, nullable=False, default=utcnow, index=True) last_at = Column(UTCDateTime, nullable=False, default=utcnow) expires_at = Column(UTCDateTime, nullable=True) # hidden (and dedupe ends) after this class NotificationRead(Base): __tablename__ = "notification_reads" notification_id = Column(Integer, ForeignKey("notifications.id", ondelete="CASCADE"), primary_key=True) user_id = Column(Integer, primary_key=True) # no FK: the support account (id 0) can read too read_at = Column(UTCDateTime, nullable=False, default=utcnow)