from typing import Optional

from pydantic import BaseModel, Field

from core.pydantic import BaseResponse


class OperationLogBase(BaseModel):
    user_id: int = Field(..., description="用户ID")
    user_name: str = Field(..., description="用户名")
    module: str = Field(..., description="模块")
    table_name: Optional[str] = Field(None, description="表名")
    record_id: Optional[int] = Field(None, description="记录ID")
    action: str = Field(
        ..., description="记录类型：CREATE, UPDATE, DELETE"
    )  # CREATE, UPDATE, DELETE
    method: str = Field(..., description="请求方法：GET, POST, PUT, DELETE")
    path: str = Field(..., description="请求路径")
    old_data: Optional[dict] = Field(None, description="旧数据")
    new_data: Optional[dict] = Field(None, description="新数据")
    ip_address: Optional[str] = Field(None, description="IP地址")
    user_agent: Optional[str] = Field(None, description="User-Agent")
    status: str = Field(..., description="操作状态：SUCCESS, FAILED")  # SUCCESS, FAILED
    error_message: Optional[str] = Field(None, description="错误信息")


class OperationLogCreate(OperationLogBase):
    pass


class OperationLogResponse(OperationLogBase, BaseResponse):
    pass
