from sqlalchemy import BigInteger, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.types import JSON

from app.models.base import BaseModel


class AgentRiskEvent(BaseModel):
    __tablename__ = "agent_risk_events"

    agent_id: Mapped[int] = mapped_column(Integer, ForeignKey("user_agents.id", ondelete="CASCADE"), nullable=False, index=True)
    user_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
    event_type: Mapped[str] = mapped_column(String(32), nullable=False, index=True)
    severity: Mapped[str] = mapped_column(String(16), default="warning", nullable=False, index=True)
    status: Mapped[str] = mapped_column(String(24), default="open", nullable=False, index=True)
    reason: Mapped[str] = mapped_column(Text, nullable=False)
    snapshot: Mapped[dict | None] = mapped_column(JSON, nullable=True)
