# _*_ coding : UTF-8 _*_
# @Time : 2025/01/27 21:41
# @UpdateTime : 2025/01/27 21:41
# @Author : sonder
# @File : log.py
# @Software : PyCharm
# @Comment : 本程序

from pydantic import BaseModel, Field

from schemas.common import BaseResponse, ListQueryResult


class LoginLogInfo(BaseModel):
    """
    登录日志信息
    """
    id: str = Field(default="", description="登录日志ID")
    user_id: str = Field(default="", description="用户ID")
    username: str = Field(default="", description="用户名")
    user_nickname: str = Field(default="", description="用户昵称")
    department_id: str = Field(default="", description="部门ID")
    department_name: str = Field(default="", description="部门名称")
    login_ip: str = Field(default="", description="登录IP")
    login_location: str = Field(default="", description="登录地点")
    browser: str = Field(default="", description="登录浏览器")
    os: str = Field(default="", description="登录操作系统")
    status: int = Field(default="", description="登录状态")
    login_time: str = Field(default="", description="登录时间")
    session_id: str = Field(default="", description="会话ID")
    online: bool = Field(default=False, description="是否在线")
    create_time: str = Field(default="", description="创建时间")
    update_time: str = Field(default="", description="更新时间")

    class Config:
        json_schema_extra = {
            "example": {
                "id": "1",
                "user_id": "1",
                "username": "admin",
                "user_nickname": "管理员",
                "department_id": "1",
                "department_name": "超级管理员",
                "login_ip": "127.0.0.1",
                "login_location": "中国",
                "browser": "Chrome",
                "os": "Windows",
                "status": 1,
                "login_time": "2025-01-27 21:41:00",
                "session_id": "1",
                "online": True,
                "create_time": "2025-01-27 21:41:00",
                "update_time": "2025-01-27 21:41:00"
            }
        }


class LoginLogResult(ListQueryResult):
    """
    登录日志查询结果
    """
    result: list[LoginLogInfo] = Field(default=[], description="登录日志列表")


class GetLoginLogResponse(BaseResponse):
    """
    获取登录日志响应
    """
    data: LoginLogResult = Field(default=[], description="登录日志查询结果")


class OperationLogInfo(BaseModel):
    """
    操作日志信息
    """
    id: str = Field(default="", description="操作日志ID")
    operation_name: str = Field(default="", description="操作名称")
    operation_type: int = Field(default=1, description="操作类型")
    request_path: str = Field(default="", description="请求路径")
    request_method: str = Field(default="", description="请求方法")
    request_params: str = Field(default="", description="请求参数")
    request_result: str = Field(default="", description="请求结果")
    host: str = Field(default="", description="请求主机")
    location: str = Field(default="", description="请求地址")
    browser: str = Field(default="", description="请求浏览器")
    os: str = Field(default="", description="请求操作系统")
    user_agent: str = Field(default="", description="请求头")
    operator_id: str = Field(default="", description="操作人员ID")
    operator_name: str = Field(default="", description="操作人员名称")
    operator_nickname: str = Field(default="", description="操作人员昵称")
    department_id: str = Field(default="", description="操作人员部门ID")
    department_name: str = Field(default="", description="操作人员部门名称")
    operation_time: str = Field(default="", description="操作时间")
    cost_time: float = Field(default=0.0, description="操作耗时")
    status: int = Field(default="", description="操作状态")

    class Config:
        json_schema_extra = {
            "example": {
                "id": "1",
                "operation_name": "登录",
                "operation_type": 1,
                "request_path": "/login",
                "request_method": "POST",
                "request_params": "{\"username\": \"admin\", \"password\": \"123456\"}",
                "request_result": "{\"code\": 200, \"data\": {\"token\":\"eyJ0eXAiOiJKV1Qi}",
                "host": "127.0.0.1",
                "location": "中国",
                "browser": "Chrome",
                "os": "Windows",
                "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
                "operator_id": "1",
                "operator_name": "admin",
                "operator_nickname": "管理员",
                "department_id": "1",
                "department_name": "超级管理员",
                "operation_time": "2025-01-27 21:41:00",
                "cost_time": 0.123,
                "status": 1
            }
        }


class OperationLogResult(ListQueryResult):
    """
    操作日志查询结果
    """
    result: list[OperationLogInfo] = Field(default=[], description="操作日志列表")


class GetOperationLogResponse(BaseResponse):
    """
    获取操作日志响应
    """
    data: OperationLogResult = Field(default=[], description="操作日志查询结果")
