# /opt/docker/dev/service_finder/backend/app/schemas/security.py
"""
Dual Control (Négy szem elv) sémák.
"""
from datetime import datetime
from typing import Optional, Dict, Any
from pydantic import BaseModel, Field

from app.models import ActionStatus

# --- Request schemas ---

class PendingActionCreate(BaseModel):
    """ Dual Control kérelem létrehozása. """
    action_type: str = Field(..., description="Művelettípus (pl. CHANGE_ROLE, SET_VIP)")
    payload: Dict[str, Any] = Field(..., description="Művelet specifikus adatok")
    reason: Optional[str] = Field(None, description="Indoklás a kérelemhez")

class PendingActionApprove(BaseModel):
    """ Művelet jóváhagyása. """
    comment: Optional[str] = Field(None, description="Opcionális megjegyzés")

class PendingActionReject(BaseModel):
    """ Művelet elutasítása. """
    reason: str = Field(..., description="Elutasítás oka")

# --- Response schemas ---

class UserLite(BaseModel):
    """ Felhasználó alapvető adatai. """
    id: int
    email: str
    role: str

    class Config:
        from_attributes = True

class PendingActionResponse(BaseModel):
    """ Dual Control művelet válasza. """
    id: int
    requester_id: int
    approver_id: Optional[int]
    status: ActionStatus
    action_type: str
    payload: Dict[str, Any]
    reason: Optional[str]
    created_at: datetime
    expires_at: datetime
    processed_at: Optional[datetime]
    
    # Kapcsolatok
    requester: Optional[UserLite] = None
    approver: Optional[UserLite] = None

    class Config:
        from_attributes = True

# --- List response ---

class PendingActionList(BaseModel):
    """ Dual Control műveletek listája. """
    items: list[PendingActionResponse]
    total: int
    page: int
    size: int