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


class ProjectImage(BaseModel):
    id: Optional[int] = Field(None, description="id")
    project_id: Optional[int] = Field(..., description="项目id")
    img_type: Optional[str] = Field(None, description="图片类别")
    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 ProjectImageOut(BaseModel):
    id: Optional[int] = Field(None, description="id")
    project_id: Optional[int] = Field(..., description="项目id")
    file_name: Optional[str] = Field(None, description="文件名称")
    create_time: Optional[datetime] = Field(None, description="上传时间")
    label_count: Optional[int]

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


class ProjectImagePager(BaseModel):
    project_id: Optional[int] = Field(..., description="项目id")
    img_type: Optional[str] = Field(None, description="图片类别")
    pagerNum: Optional[int] = Field(None, description="当前页码")
    pagerSize: Optional[int] = Field(None, description="每页数量")


class ProjectImgLabelIn(BaseModel):
    label_id: int
    mark_center_x: str
    mark_center_y: str
    mark_width: str
    mark_height: str


class ProjectImgLeaferLabel(BaseModel):
    image_id: Optional[int] = Field(..., description="图片id")
    leafer: Optional[dict] = Field(..., description="保存的leafer")
    label_infos: List[ProjectImgLabelIn] = Field(..., description="标签框选信息")


class ProjectImgLeaferOut(BaseModel):
    image_id: Optional[int] = Field(..., description="图片id")
    leafer: Optional[dict] = Field(..., description="保存的leafer")

    class Config:
        orm_mode = True
