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


class QcTaskCreate(BaseModel):
    task_code: str
    coil_no: Optional[str] = None
    task_type: Optional[str] = None
    scheme_name: Optional[str] = None
    inspect_user: Optional[str] = None
    remark: Optional[str] = None


class QcTaskUpdate(BaseModel):
    coil_no: Optional[str] = None
    task_type: Optional[str] = None
    scheme_name: Optional[str] = None
    status: Optional[int] = None
    inspect_user: Optional[str] = None
    inspect_time: Optional[datetime] = None
    audit_user: Optional[str] = None
    audit_time: Optional[datetime] = None
    result: Optional[str] = None
    remark: Optional[str] = None


class QcTaskItemOut(BaseModel):
    id: int
    task_id: int
    item_name: str
    item_type: Optional[str]
    standard_value: Optional[float]
    upper_limit: Optional[float]
    lower_limit: Optional[float]
    unit: Optional[str]
    inspect_value: Optional[str]
    is_qualified: Optional[int]
    judge_result: Optional[str]
    inspect_user: Optional[str]
    inspect_time: Optional[datetime]
    created_at: datetime
    class Config:
        from_attributes = True


class QcTaskItemCreate(BaseModel):
    task_id: int
    item_name: str
    item_type: Optional[str] = None
    standard_value: Optional[float] = None
    upper_limit: Optional[float] = None
    lower_limit: Optional[float] = None
    unit: Optional[str] = None
    inspect_value: Optional[str] = None
    is_qualified: Optional[int] = None
    judge_result: Optional[str] = None
    inspect_user: Optional[str] = None
    inspect_time: Optional[datetime] = None


class QcTaskItemUpdate(BaseModel):
    inspect_value: Optional[str] = None
    is_qualified: Optional[int] = None
    judge_result: Optional[str] = None
    inspect_user: Optional[str] = None
    inspect_time: Optional[datetime] = None


class QcTaskOut(BaseModel):
    id: int
    task_code: str
    coil_no: Optional[str]
    task_type: Optional[str]
    scheme_name: Optional[str]
    status: int
    inspect_user: Optional[str]
    inspect_time: Optional[datetime]
    audit_user: Optional[str]
    audit_time: Optional[datetime]
    result: Optional[str]
    remark: Optional[str]
    created_at: datetime
    class Config:
        from_attributes = True


class QcDefectCreate(BaseModel):
    coil_no: Optional[str] = None
    production_line: Optional[str] = None
    position: Optional[str] = None
    plate_surface: Optional[str] = None
    defect_code: Optional[str] = None
    defect_type: Optional[str] = None
    defect_rate: Optional[float] = None
    defect_weight: Optional[float] = None
    degree: Optional[str] = None
    judge_level: Optional[str] = None
    judge_by: Optional[str] = None
    judge_time: Optional[datetime] = None
    main_mark: Optional[int] = None
    whole_coil_mark: Optional[int] = None
    remark: Optional[str] = None


class QcDefectUpdate(BaseModel):
    defect_type: Optional[str] = None
    defect_rate: Optional[float] = None
    defect_weight: Optional[float] = None
    degree: Optional[str] = None
    judge_level: Optional[str] = None
    judge_by: Optional[str] = None
    judge_time: Optional[datetime] = None
    remark: Optional[str] = None


class QcDefectOut(BaseModel):
    id: int
    coil_no: Optional[str]
    production_line: Optional[str]
    position: Optional[str]
    plate_surface: Optional[str]
    defect_code: Optional[str]
    defect_type: Optional[str]
    defect_rate: Optional[float]
    defect_weight: Optional[float]
    degree: Optional[str]
    judge_level: Optional[str]
    judge_by: Optional[str]
    judge_time: Optional[datetime]
    main_mark: Optional[int]
    whole_coil_mark: Optional[int]
    remark: Optional[str]
    created_at: datetime
    class Config:
        from_attributes = True
