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


class CategoryCreate(BaseModel):
    code: str
    name: str
    category: str
    description: Optional[str] = None


class CategoryOut(BaseModel):
    id: int
    code: str
    name: str
    category: str
    description: Optional[str]
    is_active: int

    class Config:
        from_attributes = True


class DowntimeCreate(BaseModel):
    category_id: Optional[int] = None
    category_code: Optional[str] = None
    shift: Optional[str] = None
    shift_date: Optional[datetime] = None
    start_time: datetime
    end_time: Optional[datetime] = None
    equipment_code: Optional[str] = None
    fault_desc: Optional[str] = None
    action_taken: Optional[str] = None
    root_cause: Optional[str] = None
    reporter: Optional[str] = None
    handler: Optional[str] = None
    is_planned: int = 0


class DowntimeUpdate(BaseModel):
    end_time: Optional[datetime] = None
    action_taken: Optional[str] = None
    root_cause: Optional[str] = None
    handler: Optional[str] = None
    fault_desc: Optional[str] = None


class DowntimeOut(BaseModel):
    id: int
    category_code: Optional[str]
    category_name: Optional[str]
    shift: Optional[str]
    shift_date: Optional[datetime]
    start_time: datetime
    end_time: Optional[datetime]
    duration: Optional[float]
    equipment_code: Optional[str]
    fault_desc: Optional[str]
    action_taken: Optional[str]
    reporter: Optional[str]
    handler: Optional[str]
    is_planned: int
    created_at: datetime

    class Config:
        from_attributes = True
