# _*_ coding : UTF-8 _*_
# @Time : 2025/01/20 20:32
# @UpdateTime : 2025/01/20 20:32
# @Author : sonder
# @File : permission.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 PermissionInfo(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="更新时间")
    menu_type: int = Field(..., description="菜单类型（0菜单、1iframe、2外链、3按钮）")
    parent_id: str = Field(default="", max_length=36, description="父权限ID")
    title: str = Field(..., max_length=255, description="菜单名称")
    name: Optional[str] = Field(default=None, max_length=255, description="路由名称")
    path: Optional[str] = Field(default=None, max_length=255, description="路由路径")
    component: Optional[str] = Field(default=None, max_length=255, description="组件路径")
    rank: int = Field(default=1, description="菜单排序")
    redirect: Optional[str] = Field(default=None, max_length=255, description="路由重定向")
    icon: Optional[str] = Field(default=None, max_length=255, description="菜单图标")
    extra_icon: Optional[str] = Field(default=None, max_length=255, description="右侧图标")
    enter_transition: Optional[str] = Field(default=None, max_length=255, description="进场动画")
    leave_transition: Optional[str] = Field(default=None, max_length=255, description="离场动画")
    active_path: Optional[str] = Field(default=None, max_length=255, description="菜单激活路径")
    auths: Optional[str] = Field(default=None, max_length=255, description="权限标识")
    frame_src: Optional[str] = Field(default=None, max_length=255, description="iframe链接地址")
    frame_loading: bool = Field(default=True, description="iframe加载动画")
    keep_alive: bool = Field(default=False, description="缓存页面")
    hidden_tag: bool = Field(default=False, description="隐藏标签页")
    fixed_tag: bool = Field(default=False, description="固定标签页")
    show_link: bool = Field(default=True, description="显示菜单")
    show_parent: bool = Field(default=True, 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",
                "menu_type": 0,
                "parent_id": "",
                "title": "首页",
                "name": "home",
                "path": "/home",
                "component": "HomeView",
                "rank": 1,
                "redirect": None,
                "icon": "home",
                "extra_icon": None,
                "enter_transition": None,
                "leave_transition": None,
                "active_path": None,
                "auths": None,
                "frame_src": None,
                "frame_loading": True,
                "keep_alive": False,
                "hidden_tag": False,
                "fixed_tag": False,
                "show_link": True,
                "show_parent": True
            }
        }


class GetPermissionInfoResponse(BaseResponse):
    """
    获取权限信息响应模型。
    """
    data: PermissionInfo = Field(default=None, description="响应数据")


class AddPermissionParams(BaseModel):
    """
    添加权限参数模型。
    """
    name: str = Field(..., max_length=255, description="路由名称")
    path: str = Field(..., max_length=255, description="路由路径")
    title: str = Field(..., max_length=255, description="菜单名称")
    component: Optional[str] = Field(default=None, max_length=255, description="组件路径")
    rank: int = Field(default=1, description="菜单排序")
    redirect: Optional[str] = Field(default=None, max_length=255, description="路由重定向")
    icon: Optional[str] = Field(default=None, max_length=255, description="菜单图标")
    extra_icon: Optional[str] = Field(default=None, max_length=255, description="右侧图标")
    enter_transition: Optional[str] = Field(default=None, max_length=255, description="进场动画")
    leave_transition: Optional[str] = Field(default=None, max_length=255, description="离场动画")
    active_path: Optional[str] = Field(default=None, max_length=255, description="菜单激活路径")
    auths: Optional[str] = Field(default=None, max_length=255, description="权限标识")
    frame_src: Optional[str] = Field(default=None, max_length=255, description="iframe链接地址")
    frame_loading: bool = Field(default=True, description="iframe加载动画")
    keep_alive: bool = Field(default=False, description="缓存页面")
    hidden_tag: bool = Field(default=False, description="隐藏标签页")
    fixed_tag: bool = Field(default=False, description="固定标签页")
    show_link: bool = Field(default=True, description="显示菜单")
    show_parent: bool = Field(default=True, description="显示父级菜单")
    parent_id: str = Field(default="", max_length=36, description="父级菜单ID")
    menu_type: int = Field(default=0, description="菜单类型")

    class Config:
        json_schema_extra = {
            "example": {
                "name": "home",
                "path": "/home",
                "title": "首页",
                "component": "HomeView",
                "rank": 1,
                "redirect": None,
                "icon": "home",
                "extra_icon": None,
                "enter_transition": None,
                "leave_transition": None,
                "active_path": None,
                "auths": None,
                "frame_src": None,
                "frame_loading": True,
                "keep_alive": False,
                "hidden_tag": False,
                "fixed_tag": False,
                "show_link": True,
                "show_parent": True,
                "parent_id": "",
                "menu_type": 0
            }
        }


class GetPermissionListResult(ListQueryResult):
    """
    获取权限列表结果模型。
    """
    result: List[PermissionInfo] = Field(default=[], description="权限列表")


class GetPermissionListResponse(BaseResponse):
    """
    获取权限列表响应模型。
    """
    data: GetPermissionListResult = Field(default=None, description="响应数据")
