"""Pydantic schemas for approval requests API."""

from typing import Optional, List, Any, Dict, Literal
from pydantic import BaseModel, Field


class ApprovalRequestCreate(BaseModel):
    """Request model for creating an approval request (called by enforcement hook)."""
    execution_id: str
    rule_id: Optional[str] = None
    tool_name: str
    tool_args: Optional[Dict[str, Any]] = None
    risk_level: Optional[str] = None
    enforcement_context: Optional[Dict[str, Any]] = None
    approver_emails: Optional[List[str]] = None
    timeout_minutes: int = Field(default=1440, ge=1)


class ApprovalRequestResponse(BaseModel):
    """Response model for an approval request."""
    id: str
    organization_id: str
    execution_id: str
    rule_id: Optional[str] = None
    status: str
    requester_email: Optional[str] = None
    requester_id: Optional[str] = None
    tool_name: str
    tool_args: Optional[Dict[str, Any]] = None
    risk_level: Optional[str] = None
    enforcement_context: Optional[Dict[str, Any]] = None
    approver_emails: Optional[List[str]] = None
    approved_by_email: Optional[str] = None
    approved_by_name: Optional[str] = None
    rejection_reason: Optional[str] = None
    resolved_at: Optional[str] = None
    expires_at: Optional[str] = None
    created_at: Optional[str] = None
    updated_at: Optional[str] = None

    model_config = {"from_attributes": True}


class ApproveRequestBody(BaseModel):
    """Request body for approving a request."""
    comment: Optional[str] = None


class RejectRequestBody(BaseModel):
    """Request body for rejecting a request."""
    reason: Optional[str] = None
