from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from pydantic_validation_decorator import NotBlank
from typing import Optional
from module_admin.annotation.pydantic_annotation import as_query




class RoleModel(BaseModel):
    """
    系统角色表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    robot_role_id: Optional[int] = Field(default=None, description='机器人角色ID')
    rolename: Optional[str] = Field(default=None, description='角色名称')
    detail: Optional[str] = Field(default=None, description='角色介绍')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')
    create_by: Optional[str] = Field(default=None, description='创建者')
    update_time: Optional[datetime] = Field(default=None, description='修改时间')
    update_by: Optional[str] = Field(default=None, description='修改者')
    remark: Optional[str] = Field(default=None, description='备注')

    @NotBlank(field_name='rolename', message='角色名称不能为空')
    def get_rolename(self):
        return self.rolename

    @NotBlank(field_name='create_time', message='创建时间不能为空')
    def get_create_time(self):
        return self.create_time

    @NotBlank(field_name='create_by', message='创建者不能为空')
    def get_create_by(self):
        return self.create_by

    @NotBlank(field_name='update_time', message='修改时间不能为空')
    def get_update_time(self):
        return self.update_time

    @NotBlank(field_name='update_by', message='修改者不能为空')
    def get_update_by(self):
        return self.update_by


    def validate_fields(self):
        self.get_rolename()
        self.get_create_time()
        self.get_create_by()
        self.get_update_time()
        self.get_update_by()




class RoleQueryModel(RoleModel):
    """
    系统角色不分页查询模型
    """
    begin_create_time: Optional[str] = Field(default=None, description='开始创建时间')
    end_create_time: Optional[str] = Field(default=None, description='结束创建时间')
    begin_update_time: Optional[str] = Field(default=None, description='开始修改时间')
    end_update_time: Optional[str] = Field(default=None, description='结束修改时间')


@as_query
class RolePageQueryModel(RoleQueryModel):
    """
    系统角色分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeleteRoleModel(BaseModel):
    """
    删除系统角色模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    robot_role_ids: str = Field(description='需要删除的机器人角色ID')
