# _*_ coding : UTF-8 _*_
# @Time : 2025/01/19 02:19
# @UpdateTime : 2025/01/19 02:19
# @Author : sonder
# @File : department.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 DepartmentInfo(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=100, description="部门名称")
    parent_id: Optional[str] = Field(default=None, max_length=36, description="父部门ID")
    sort: int = Field(default=0, description="排序权重（0最高）")
    phone: Optional[str] = Field(default=None, max_length=30, description="部门电话")
    principal: str = Field(..., max_length=64, description="部门负责人")
    email: Optional[str] = Field(default=None, max_length=128, description="部门邮箱")
    remark: Optional[str] = Field(default=None, max_length=255, description="备注信息")
    status: Optional[int] = Field(default=None, 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": "研发部",
                "parent_id": "",
                "sort": 0,
                "phone": "1234567890",
                "principal": "张三",
                "email": "dev@example.com",
                "remark": "研发部门",
                "status": 1
            }
        }


class GetDepartmentInfoResponse(BaseResponse):
    """
    获取部门信息响应模型。
    """
    data: DepartmentInfo = Field(default=None, description="响应数据")


class AddDepartmentParams(BaseModel):
    """
    添加部门参数模型。
    """
    name: str = Field(..., max_length=100, description="部门名称")
    parent_id: Optional[str] = Field(default=None, max_length=36, description="父部门ID")
    sort: int = Field(default=0, description="排序权重（0最高）")
    phone: Optional[str] = Field(default=None, max_length=30, description="部门电话")
    principal: str = Field(..., max_length=64, description="部门负责人")
    email: Optional[str] = Field(default=None, max_length=128, description="部门邮箱")
    remark: Optional[str] = Field(default=None, max_length=255, description="备注信息")
    status: Optional[int] = Field(default=None, description="状态")

    class Config:
        json_schema_extra = {
            "example": {
                "name": "研发部",
                "parent_id": "",
                "sort": 0,
                "phone": "1234567890",
                "principal": "张三",
                "email": "dev@example.com",
                "remark": "研发部门",
                "status": 1
            }
        }


class GetDepartmentListResult(ListQueryResult):
    """
    获取部门列表结果模型。
    """
    result: List[DepartmentInfo] = Field(default=[], description="部门列表")


class GetDepartmentListResponse(BaseResponse):
    """
    获取部门列表响应模型。
    """
    data: GetDepartmentListResult = Field(default=None, description="响应数据")
