from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime


class ProjectDetectIn(BaseModel):
    project_id: Optional[int] = Field(..., description="项目id")
    file_type: Optional[str] = Field('img', description="推理集合文件类别")
    detect_name: Optional[str] = Field(..., description="推理集合名称")
    rtsp_url: Optional[str] = Field(None, description="视频流地址")


class ProjectDetectPager(BaseModel):
    project_id: Optional[int] = Field(..., description="项目id")
    detect_name: Optional[str] = Field(None, description="推理集合名称")
    pagerNum: Optional[int] = Field(1, description="当前页码")
    pagerSize: Optional[int] = Field(10, description="每页数量")


class ProjectDetectOut(BaseModel):
    id: Optional[int]
    project_id: Optional[int]
    detect_name: Optional[str]
    detect_no: Optional[str]
    detect_version: Optional[int]
    file_type: Optional[str]
    folder_url: Optional[str]
    rtsp_url: Optional[str]
    create_time: Optional[datetime]

    class Config:
        orm_mode = True
        json_encoders = {
            datetime: lambda v: v.strftime("%Y-%m-%d %H:%M:%S")
        }


class ProjectDetectList(BaseModel):
    id: Optional[int]
    file_type: Optional[str]
    detect_name: Optional[str]

    class Config:
        orm_mode = True


class ProjectDetectImgPager(BaseModel):
    detect_id: Optional[int] = Field(..., description="训练集合id")
    pagerNum: Optional[int] = Field(None, description="当前页码")
    pagerSize: Optional[int] = Field(None, description="每页数量")


class ProjectDetectImageOut(BaseModel):
    id: Optional[int] = Field(None, description="id")
    detect_id: Optional[int] = Field(..., description="训练集合id")
    file_name: Optional[str] = Field(None, description="文件名称")
    create_time: Optional[datetime] = Field(None, description="上传时间")

    class Config:
        orm_mode = True
        json_encoders = {
            datetime: lambda v: v.strftime("%Y-%m-%d %H:%M:%S")
        }


class ProjectDetectLogIn(BaseModel):
    detect_id: Optional[int] = Field(..., description="推理集合id")
    train_id: Optional[int] = Field(..., description="训练结果id")
    pt_type: Optional[str] = Field('best', description="权重文件类型")


class ProjectDetectLogPager(BaseModel):
    detect_id: Optional[int] = Field(..., description="推理集合id")
    pagerNum: Optional[int] = Field(None, description="当前页码")
    pagerSize: Optional[int] = Field(None, description="每页数量")


class ProjectDetectLogOut(BaseModel):
    id: Optional[int]
    detect_id: Optional[int]
    detect_version: Optional[str]
    detect_name: Optional[str]
    train_id: Optional[int]
    train_version: Optional[str]
    pt_type: Optional[str]
    create_time: Optional[datetime]

    class Config:
        orm_mode = True
        json_encoders = {
            datetime: lambda v: v.strftime("%Y-%m-%d %H:%M:%S")
        }


class ProjectDetectLogImgOut(BaseModel):
    id: Optional[int]
    file_name: Optional[str]
    create_time: Optional[datetime]

    class Config:
        orm_mode = True
        json_encoders = {
            datetime: lambda v: v.strftime("%Y-%m-%d %H:%M:%S")
        }


