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


class QualityRecordCreate(BaseModel):
    coil_no:              str
    production_record_id: Optional[int]   = None
    thickness_actual:     Optional[float] = None
    width_actual:         Optional[float] = None
    flatness:             Optional[float] = None
    crown:                Optional[float] = None
    surface_defect_type:  Optional[str]   = None
    defect_length_m:      Optional[float] = None
    defect_position:      Optional[str]   = None
    pi_score:             Optional[float] = None
    surface_score:        Optional[float] = None
    overall_grade:        Optional[str]   = None
    acid_residual:        Optional[float] = None
    roughness_ra:         Optional[float] = None
    inspector:            Optional[str]   = None
    inspect_time:         Optional[datetime] = None
    is_passed:            Optional[bool]  = True


class QualityRecordUpdate(BaseModel):
    thickness_actual:     Optional[float] = None
    width_actual:         Optional[float] = None
    flatness:             Optional[float] = None
    crown:                Optional[float] = None
    surface_defect_type:  Optional[str]   = None
    defect_length_m:      Optional[float] = None
    defect_position:      Optional[str]   = None
    pi_score:             Optional[float] = None
    surface_score:        Optional[float] = None
    overall_grade:        Optional[str]   = None
    acid_residual:        Optional[float] = None
    roughness_ra:         Optional[float] = None
    inspector:            Optional[str]   = None
    inspect_time:         Optional[datetime] = None
    is_passed:            Optional[bool]  = None


class QualityRecordOut(BaseModel):
    id:                   int
    coil_no:              str
    production_record_id: Optional[int]
    thickness_actual:     Optional[float]
    width_actual:         Optional[float]
    flatness:             Optional[float]
    crown:                Optional[float]
    surface_defect_type:  Optional[str]
    defect_length_m:      Optional[float]
    defect_position:      Optional[str]
    pi_score:             Optional[float]
    surface_score:        Optional[float]
    overall_grade:        Optional[str]
    acid_residual:        Optional[float]
    roughness_ra:         Optional[float]
    inspector:            Optional[str]
    inspect_time:         Optional[datetime]
    is_passed:            Optional[bool]
    created_at:           datetime

    class Config:
        from_attributes = True
