from pydantic import BaseModel
from typing import Optional
from datetime import datetime
from app.models.material import CoilStatus


class CoilCreate(BaseModel):
    coil_no: str
    order_no: Optional[str] = None
    steel_grade: Optional[str] = None
    spec_thickness: Optional[float] = None
    spec_width: Optional[float] = None
    target_thickness: Optional[float] = None
    target_width: Optional[float] = None
    gross_weight: Optional[float] = None
    net_weight: Optional[float] = None
    inner_diameter: Optional[float] = None
    plan_id: Optional[int] = None
    remark: Optional[str] = None


class CoilUpdate(BaseModel):
    order_no: Optional[str] = None
    steel_grade: Optional[str] = None
    spec_thickness: Optional[float] = None
    spec_width: Optional[float] = None
    target_thickness: Optional[float] = None
    target_width: Optional[float] = None
    gross_weight: Optional[float] = None
    net_weight: Optional[float] = None
    status: Optional[CoilStatus] = None
    plan_id: Optional[int] = None
    remark: Optional[str] = None


class CoilOut(BaseModel):
    id: int
    coil_no: str
    order_no: Optional[str]
    steel_grade: Optional[str]
    spec_thickness: Optional[float]
    spec_width: Optional[float]
    target_thickness: Optional[float]
    target_width: Optional[float]
    gross_weight: Optional[float]
    net_weight: Optional[float]
    status: CoilStatus
    plan_id: Optional[int]
    created_at: datetime

    class Config:
        from_attributes = True


class TrackingCreate(BaseModel):
    coil_no: str
    position: Optional[str] = None
    event_type: str
    event_desc: Optional[str] = None
    actual_thickness: Optional[float] = None
    actual_width: Optional[float] = None
    speed: Optional[float] = None
    tension: Optional[float] = None
    operator: Optional[str] = None
    event_time: datetime


class TrackingOut(BaseModel):
    id: int
    coil_id: int
    coil_no: str
    position: Optional[str]
    event_type: str
    event_desc: Optional[str]
    actual_thickness: Optional[float]
    actual_width: Optional[float]
    speed: Optional[float]
    operator: Optional[str]
    event_time: datetime

    class Config:
        from_attributes = True
