# _*_ coding : UTF-8 _*_
# @Time : 2025/01/20 22:40
# @UpdateTime : 2025/01/20 22:40
# @Author : sonder
# @File : role.py
# @Software : PyCharm
# @Comment : 本程序
from datetime import datetime
from typing import Optional, List

from pydantic import BaseModel, Field

from schemas.common import BaseResponse, ListQueryResult


class RoleInfo(BaseModel):
    """
    角色表基础模型。
    """
    id: str = Field(..., description="主键")
    create_by: str = Field(default="", description="创建者")
    create_time: Optional[datetime] = Field(default=None, description="创建时间")
    update_by: str = Field(default="", description="更新者")
    update_time: Optional[datetime] = Field(default=None, description="更新时间")
    name: str = Field(..., max_length=255, description="角色名称")
    code: str = Field(..., max_length=255, description="角色编码")
    status: int = Field(default=1, description="状态")
    description: Optional[str] = Field(default=None, max_length=255, description="角色描述")
    department_id: Optional[str] = Field(default=None, max_length=36, description="所属部门ID")
    department_name: Optional[str] = Field(default=None, max_length=255, description="所属部门名称")
    department_phone: Optional[str] = Field(default=None, max_length=255, description="所属部门电话")
    department_principal: Optional[str] = Field(default=None, max_length=255, description="所属部门领导人")
    department_email: Optional[str] = Field(default=None, max_length=255, description="所属部门邮件")

    class Config:
        json_schema_extra = {
            "example": {
                "id": "550e8400-e29b-41d4-a716-446655440000",
                "create_by": "admin",
                "create_time": "2023-10-01T12:00:00",
                "update_by": "admin",
                "update_time": "2023-10-01T12:00:00",
                "name": "管理员",
                "code": "admin",
                "status": 1,
                "description": "系统管理员角色",
                "department_id": "770e8400-e29b-41d4-a716-446655440000",
                "department_name": "技术部",
                "department_phone": "1234567890",
                "department_principal": "张三",
                "department_email": "zhangsan@example.com"
            }
        }


class GetRoleInfoResponse(BaseResponse):
    """
    获取角色信息响应模型。
    """
    data: RoleInfo = Field(default=None, description="角色信息")


class AddRoleParams(BaseModel):
    """
    添加角色请求参数模型。
    """
    name: str = Field(..., max_length=255, description="角色名称")
    code: str = Field(..., max_length=255, description="角色编码")
    description: Optional[str] = Field(default=None, max_length=255, description="角色描述")
    department_id: Optional[str] = Field(default=None, max_length=36, description="所属部门ID")
    status: Optional[int] = Field(default=1, description="状态")

    class Config:
        json_schema_extra = {
            "example": {
                "name": "管理员",
                "code": "admin",
                "description": "系统管理员角色",
                "department_id": "770e8400-e29b-41d4-a716-446655440000",
                "status": 1
            }
        }


class GetRoleListResult(ListQueryResult):
    """
    获取角色列表结果模型。
    """
    result: List[RoleInfo] = Field(default=None, description="角色列表")


class GetRoleListResponse(BaseResponse):
    """
    获取角色列表响应模型。
    """
    data: GetRoleListResult = Field(default=None, description="角色列表结果")


class AddRolePermissionParams(BaseModel):
    """
    添加角色权限请求参数模型。
    """
    permission_ids: List[str] = Field(..., description="权限ID列表")

    class Config:
        json_schema_extra = {
            "example": {
                "permission_ids": ["1", "2", "3"]
            }
        }


class RolePermissionInfo(BaseModel):
    """
    角色权限信息模型。
    """
    id: str = Field(..., description="主键")
    create_by: str = Field(default="", description="创建者")
    create_time: Optional[datetime] = Field(default=None, description="创建时间")
    update_by: str = Field(default="", description="更新者")
    update_time: Optional[datetime] = Field(default=None, description="更新时间")
    role_id: str = Field(..., max_length=36, description="角色ID")
    role_code: str = Field(..., max_length=255, description="角色编码")
    role_name: str = Field(..., max_length=255, description="角色名称")
    permission_id: str = Field(..., max_length=36, description="权限ID")
    permission__parent_id: str = Field(default="", max_length=36, description="父级权限ID")
    permission_name: str = Field(..., max_length=255, description="权限名称")
    permission_code: str = Field(..., max_length=255, description="权限编码")
    permission_type: str = Field(..., max_length=255, description="权限类型")

    class Config:
        json_schema_extra = {
            "example": {
                "id": "550e8400-e29b-41d4-a716-446655440000",
                "create_by": "admin",
                "create_time": "2023-10-01T12:00:00",
                "update_by": "admin",
                "update_time": "2023-10-01T12:00:00",
                "role_id": "550e8400-e29b-41d4-a716-446655440000",
                "role_code": "admin",
                "role_name": "管理员",
                "permission_id": "550e8400-e29b-41d4-a716-446655440000",
                "permission__parent_id": "550e8400-e29b-41d4-a716-446655440000",
                "permission_name": "权限名称",
                "permission_code": "admin",
                "permission_type": "admin"
            }
        }


class GetRolePermissionInfoResponse(BaseResponse):
    """
    获取角色权限信息响应模型。
    """
    data: RolePermissionInfo = Field(default=None, description="角色权限信息")


class GetRolePermissionListResult(ListQueryResult):
    """
    获取角色权限列表结果模型。
    """
    result: List[RolePermissionInfo] = Field(default=None, description="角色权限列表")


class GetRolePermissionListResponse(BaseResponse):
    """
    获取角色权限列表响应模型。
    """
    data: GetRolePermissionListResult = Field(default=None, description="角色权限列表结果")
