from pydantic import BaseModel
from typing import Optional
from datetime import datetime


class ProductionRecordCreate(BaseModel):
    coil_no: str
    sub_coil_no: Optional[str] = None
    hot_coil_no: Optional[str] = None
    plan_id: Optional[int] = None
    shift: Optional[str] = None
    team: Optional[str] = None
    steel_grade: Optional[str] = None
    incoming_thickness: Optional[float] = None
    outlet_thickness: Optional[float] = None
    deviation_upper: Optional[float] = None
    deviation_lower: Optional[float] = None
    incoming_width: Optional[float] = None
    outlet_width: Optional[float] = None
    incoming_weight: Optional[float] = None
    weighed_weight: Optional[float] = None
    packaging_req: Optional[str] = None
    trim_req: Optional[str] = None
    surface_quality: Optional[str] = None
    product_quality: Optional[float] = None
    product_length: Optional[float] = None
    length_per_ton: Optional[float] = None
    offline_time: Optional[datetime] = None
    status: Optional[str] = "UNWEIGH"
    remark: Optional[str] = None


class ProductionRecordUpdate(BaseModel):
    sub_coil_no: Optional[str] = None
    hot_coil_no: Optional[str] = None
    shift: Optional[str] = None
    team: Optional[str] = None
    steel_grade: Optional[str] = None
    incoming_thickness: Optional[float] = None
    outlet_thickness: Optional[float] = None
    deviation_upper: Optional[float] = None
    deviation_lower: Optional[float] = None
    incoming_width: Optional[float] = None
    outlet_width: Optional[float] = None
    incoming_weight: Optional[float] = None
    weighed_weight: Optional[float] = None
    packaging_req: Optional[str] = None
    trim_req: Optional[str] = None
    surface_quality: Optional[str] = None
    product_quality: Optional[float] = None
    product_length: Optional[float] = None
    length_per_ton: Optional[float] = None
    offline_time: Optional[datetime] = None
    status: Optional[str] = None
    remark: Optional[str] = None


class ProductionRecordOut(BaseModel):
    id: int
    coil_no: str
    sub_coil_no: Optional[str] = None
    hot_coil_no: Optional[str] = None
    plan_id: Optional[int] = None
    shift: Optional[str] = None
    team: Optional[str] = None
    steel_grade: Optional[str] = None
    incoming_thickness: Optional[float] = None
    outlet_thickness: Optional[float] = None
    deviation_upper: Optional[float] = None
    deviation_lower: Optional[float] = None
    incoming_width: Optional[float] = None
    outlet_width: Optional[float] = None
    incoming_weight: Optional[float] = None
    weighed_weight: Optional[float] = None
    packaging_req: Optional[str] = None
    trim_req: Optional[str] = None
    surface_quality: Optional[str] = None
    product_quality: Optional[float] = None
    product_length: Optional[float] = None
    length_per_ton: Optional[float] = None
    offline_time: Optional[datetime] = None
    status: Optional[str] = None
    remark: Optional[str] = None
    # 生产阶段数据
    shift_date: Optional[datetime] = None
    start_time: Optional[datetime] = None
    end_time: Optional[datetime] = None
    process_length: Optional[float] = None
    process_weight: Optional[float] = None
    avg_speed: Optional[float] = None
    max_speed: Optional[float] = None
    acid_consumption: Optional[float] = None
    inlet_thickness: Optional[float] = None
    inlet_width: Optional[float] = None
    quality_grade: Optional[str] = None
    operator: Optional[str] = None
    process_data: Optional[dict] = None
    created_at: datetime

    class Config:
        from_attributes = True
