from __future__ import annotations

from datetime import datetime
from typing import Dict, List, Optional

from pydantic import BaseModel, ConfigDict, Field


class SecurityCheckRequest(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    system_prompt: Optional[str] = Field(None, alias="system_prompt")
    user_input: Optional[str] = Field(None, alias="user_input")
    response: Optional[str] = None
    event_id: Optional[str] = Field(None, alias="event_id")
    security_checks: List[str] = Field(
        default_factory=list,
        alias="securityChecks",
        description="Requested security check identifiers",
    )


class SecurityCheckResult(BaseModel):
    id: str
    name: str
    safe: bool
    details: Optional[str] = None


class FirewallResponse(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    overall_safe: bool = Field(alias="overallSafe")
    checks: List[SecurityCheckResult]
    filtered: bool = False
    filter_message: Optional[str] = Field(None, alias="filterMessage")
    credits_used: int = Field(0, alias="creditsUsed")
    timestamp: datetime = Field(default_factory=datetime.utcnow)
    preclassification: Optional[Dict[str, object]] = None


class FirewallHistoryItem(FirewallResponse):
    model_config = ConfigDict(populate_by_name=True)

    user_id: str = Field(..., alias="userId")
    source: str
