from datetime import datetime

from sqlalchemy import Boolean, DateTime, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from backend.database.session import Base


class Alert(Base):
    __tablename__ = "alerts"

    id: Mapped[str] = mapped_column(String, primary_key=True)

    event: Mapped[str] = mapped_column(String)
    category: Mapped[str] = mapped_column(String)
    tier: Mapped[str] = mapped_column(String)

    headline: Mapped[str | None] = mapped_column(Text)
    description: Mapped[str | None] = mapped_column(Text)
    instruction: Mapped[str | None] = mapped_column(Text)

    effective: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
    expires: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))

    active: Mapped[bool] = mapped_column(Boolean, default=True)


# NEW: Discord message tracking (CRITICAL FOR UPDATES)
class AlertMessage(Base):
    __tablename__ = "alert_messages"

    alert_id: Mapped[str] = mapped_column(String, primary_key=True)

    channel_id: Mapped[int] = mapped_column(Integer)
    message_id: Mapped[int] = mapped_column(Integer)

    last_updated: Mapped[datetime] = mapped_column(DateTime(timezone=True))
