"""
Audit Log Schemas
"""

from typing import Optional, List, Any, Dict
from datetime import date as date_type, time as time_type, datetime
from pydantic import BaseModel, Field

# --- Response Schemas ---

class AuditLogResponse(BaseModel):
    """
    Standard response showing the Legacy columns
    """
    spec_id: int
    reference: str
    procedure: str
    movement: str
    username: str
    date: date_type
    time: time_type
    
    # Modern extras
    timestamp: datetime
    system: str
    operation_type: Optional[str] = None
    table_name: Optional[str] = None
    record_id: Optional[str] = None
    
    class Config:
        from_attributes = True

class AuditLogDetailResponse(AuditLogResponse):
    """
    Detailed response including changed values
    """
    old_values: Optional[Dict[str, Any]] = None
    new_values: Optional[Dict[str, Any]] = None
    changed_fields: Optional[List[str]] = None
    ip_address: Optional[str] = None
    execution_time_ms: Optional[int] = None

# --- List Response ---

class AuditLogListResponse(BaseModel):
    """
    Paginated response
    """
    data: List[AuditLogResponse]
    total: int
    page: int
    page_size: int


class AuditFileBreadcrumb(BaseModel):
    path: str = Field(default="")
    display_name: str


class AuditFileFolderItem(BaseModel):
    path: str = Field(description="Ruta relativa interna del archivo, para navegación.")
    display_name: str


class AuditFileObjectItem(BaseModel):
    path: str = Field(description="Ruta relativa interna del archivo, para descarga.")
    display_name: str
    size: int
    last_modified: Optional[datetime] = None


class AuditFileBrowserResponse(BaseModel):
    current_path: str = Field(default="")
    display_path: str = Field(default="")
    breadcrumbs: List[AuditFileBreadcrumb]
    folders: List[AuditFileFolderItem]
    files: List[AuditFileObjectItem]
    next_token: Optional[str] = None
