# app/modules/messaging/models/admin_notification.py
"""
Admin notification database model.

This model handles admin-specific notifications for system alerts and warnings.
"""

from sqlalchemy import (
    JSON,
    Boolean,
    Column,
    DateTime,
    ForeignKey,
    Integer,
    String,
    Text,
)
from sqlalchemy.orm import relationship

from app.core.database import Base
from models.database.base import TimestampMixin


class AdminNotification(Base, TimestampMixin):
    """
    Admin-specific notifications for system alerts and warnings.

    Different from store/customer notifications - these are for platform
    administrators to track system health and issues requiring attention.
    """

    __tablename__ = "admin_notifications"

    id = Column(Integer, primary_key=True, index=True)
    type = Column(
        String(50), nullable=False, index=True
    )  # system_alert, store_issue, import_failure
    priority = Column(
        String(20), default="normal", index=True
    )  # low, normal, high, critical
    title = Column(String(200), nullable=False)
    message = Column(Text, nullable=False)
    is_read = Column(Boolean, default=False, index=True)
    read_at = Column(DateTime, nullable=True)
    read_by_user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
    action_required = Column(Boolean, default=False, index=True)
    action_url = Column(String(500))  # Link to relevant admin page
    notification_metadata = Column(JSON)  # Additional contextual data

    # Relationships
    read_by = relationship("User", foreign_keys=[read_by_user_id])

    def __repr__(self):
        return f"<AdminNotification(id={self.id}, type='{self.type}', priority='{self.priority}')>"
