from pydantic import BaseModel
from typing import Optional
from datetime import datetime
from app.models.pdi import L3Status, L2Status


class PDIRecordCreate(BaseModel):
    coil_no:          str
    order_no:         Optional[str] = None
    customer:         Optional[str] = None
    steel_grade:      Optional[str] = None
    thickness:        Optional[float] = None
    width:            Optional[float] = None
    target_thickness: Optional[float] = None
    target_width:     Optional[float] = None
    yield_strength:   Optional[float] = None
    tensile_strength: Optional[float] = None
    elongation:       Optional[float] = None
    coil_weight:      Optional[float] = None
    inner_diameter:   Optional[float] = None
    outer_diameter:   Optional[float] = None
    process_route:    Optional[str]   = None
    priority:         Optional[int]   = 3
    l3_status:        Optional[L3Status] = L3Status.pending
    l2_status:        Optional[L2Status] = L2Status.pending
    send_time:        Optional[datetime] = None
    confirm_time:     Optional[datetime] = None
    remark:           Optional[str] = None


class PDIRecordUpdate(BaseModel):
    order_no:         Optional[str] = None
    customer:         Optional[str] = None
    steel_grade:      Optional[str] = None
    thickness:        Optional[float] = None
    width:            Optional[float] = None
    target_thickness: Optional[float] = None
    target_width:     Optional[float] = None
    yield_strength:   Optional[float] = None
    tensile_strength: Optional[float] = None
    elongation:       Optional[float] = None
    coil_weight:      Optional[float] = None
    inner_diameter:   Optional[float] = None
    outer_diameter:   Optional[float] = None
    process_route:    Optional[str]   = None
    priority:         Optional[int]   = None
    l3_status:        Optional[L3Status] = None
    l2_status:        Optional[L2Status] = None
    send_time:        Optional[datetime] = None
    confirm_time:     Optional[datetime] = None
    remark:           Optional[str] = None


class PDIRecordOut(BaseModel):
    id:               int
    coil_no:          str
    order_no:         Optional[str]
    customer:         Optional[str]
    steel_grade:      Optional[str]
    thickness:        Optional[float]
    width:            Optional[float]
    target_thickness: Optional[float]
    target_width:     Optional[float]
    yield_strength:   Optional[float]
    tensile_strength: Optional[float]
    elongation:       Optional[float]
    coil_weight:      Optional[float]
    inner_diameter:   Optional[float]
    outer_diameter:   Optional[float]
    process_route:    Optional[str]
    priority:         Optional[int]
    l3_status:        Optional[L3Status]
    l2_status:        Optional[L2Status]
    send_time:        Optional[datetime]
    confirm_time:     Optional[datetime]
    remark:           Optional[str]
    created_at:       datetime
    updated_at:       Optional[datetime]

    class Config:
        from_attributes = True
