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 MessageModel(BaseModel):
    """
    系统消息表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    message_id: Optional[int] = Field(default=None, description='消息主键')
    type: Optional[str] = Field(default=None, description='类型（0告警消息）')
    status: Optional[str] = Field(default=None, description='状态（0未处理，1已处理）')
    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='备注')
    specific_type: Optional[str] = Field(default=None, description='具体类型')

    # @NotBlank(field_name='type', message='类型不能为空')
    # def get_type(self):
    #     return self.type
    #
    # @NotBlank(field_name='status', message='状态不能为空')
    # def get_status(self):
    #     return self.status
    #
    # @NotBlank(field_name='create_time', message='创建时间不能为空')
    # def get_create_time(self):
    #     return self.create_time
    #
    # @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_type()
    #     self.get_status()
    #     self.get_create_time()
    #     self.get_update_time()
    #     self.get_update_by()




class MessageQueryModel(BaseModel):
    """
    系统消息不分页查询模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    type: Optional[str] = Field(default=None, description='类型（0告警消息）')
    status: Optional[str] = Field(default=None, description='状态（0未处理，1已处理）')

    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='结束更新时间')

# 编辑消息类
class EditMessageModel(BaseModel):
    """
    系统消息编辑模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    message_id: int = Field(default=None, description='消息主键')
    status: Optional[str] = Field(default=None, description='状态（0未处理，1已处理）')
    remark: Optional[str] = Field(default=None, description='备注')
    update_time: Optional[datetime] = Field(default=None, description='更新时间')
    update_by: Optional[str] = Field(default=None, description='更新者')



@as_query
class MessagePageQueryModel(MessageQueryModel):
    """
    系统消息分页查询模型
    """

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


class DeleteMessageModel(BaseModel):
    """
    删除系统消息模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    message_ids: str = Field(description='需要删除的消息主键')
