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 InfoModel(BaseModel):
    """
    机器人信息表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    robot_id: Optional[int] = Field(default=None, description='机器人ID')
    name: Optional[str] = Field(default=None, description='机器人名称')
    model: Optional[str] = Field(default=None, description='机器人型号')
    serial: Optional[str] = Field(default=None, description='序列号')
    online: Optional[str] = Field(default=None, description='机器人在线状态(0在线, 1离线)')
    power: Optional[str] = Field(default=None, description='电量')
    run_time: Optional[int] = Field(default=None, description='总运行时长（单位：分钟）')
    position: Optional[str] = Field(default=None, description='位置')
    image: 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='修改者')
    del_flag: Optional[str] = Field(default=None, description='删除标志(0存在, 2删除)')
    remark: Optional[str] = Field(default=None, description='备注')
    last_charge: Optional[datetime] = Field(default=None, description='上一次充电时间')
    ip: Optional[str] = Field(default=None, description='机器人ip')
    status: Optional[str] = Field(default=None, description='使用情况(0待机,1正在运行)')
    video_uri: Optional[str] = Field(default=None, description='视频uri')


    @NotBlank(field_name='name', message='机器人名称不能为空')
    def get_name(self):
        return self.name

    # @NotBlank(field_name='del_flag', message='删除标志(0存在, 2删除)不能为空')
    # def get_del_flag(self):
    #     return self.del_flag


    def validate_fields(self):
        self.get_name()
        # self.get_del_flag()




class InfoQueryModel(InfoModel):
    """
    机器人信息不分页查询模型
    """
    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 InfoPageQueryModel(InfoQueryModel):
    """
    机器人信息分页查询模型
    """

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


class InfoUpdateModel(BaseModel):
    """
    更新机器人信息模型
    """

    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    robot_id: Optional[int] = Field(default=None, description='机器人ID')

    name: Optional[str] = Field(default=None, description='机器人名称')
    model: Optional[str] = Field(default=None, description='机器人型号')
    serial: Optional[str] = Field(default=None, description='序列号')
    position: Optional[str] = Field(default=None, description='位置')
    image: Optional[str] = Field(default=None, description='机器人外观图地址')
    remark: Optional[str] = Field(default=None, description='备注')
    update_time: Optional[datetime] = Field(default=None, description='修改时间')
    update_by: Optional[str] = Field(default=None, description='修改者')


class DeleteInfoModel(BaseModel):
    """
    删除机器人信息模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

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