from pydantic import BaseModel
from typing import Optional
from datetime import datetime
from app.models.equipment import EquipmentStatus


class EquipmentCreate(BaseModel):
    code: str
    name: str
    category: Optional[str] = None
    model: Optional[str] = None
    manufacturer: Optional[str] = None
    install_date: Optional[datetime] = None
    location: Optional[str] = None
    rated_power: Optional[float] = None
    remark: Optional[str] = None


class EquipmentUpdate(BaseModel):
    name: Optional[str] = None
    category: Optional[str] = None
    model: Optional[str] = None
    location: Optional[str] = None
    status: Optional[EquipmentStatus] = None
    remark: Optional[str] = None


class EquipmentOut(BaseModel):
    id: int
    code: str
    name: str
    category: Optional[str]
    model: Optional[str]
    manufacturer: Optional[str]
    install_date: Optional[datetime]
    location: Optional[str]
    status: EquipmentStatus
    rated_power: Optional[float]
    created_at: datetime

    class Config:
        from_attributes = True


class MaintenanceCreate(BaseModel):
    equipment_id: int
    equipment_code: Optional[str] = None
    maintenance_type: str
    title: str
    description: Optional[str] = None
    start_time: datetime
    end_time: Optional[datetime] = None
    duration: Optional[float] = None
    cost: Optional[float] = None
    spare_parts: Optional[str] = None
    technician: Optional[str] = None
    approver: Optional[str] = None
    next_maintenance: Optional[datetime] = None
    result: Optional[str] = None
    remark: Optional[str] = None


class MaintenanceOut(BaseModel):
    id: int
    equipment_id: int
    equipment_code: Optional[str]
    maintenance_type: str
    title: str
    description: Optional[str]
    start_time: datetime
    end_time: Optional[datetime]
    duration: Optional[float]
    cost: Optional[float]
    technician: Optional[str]
    result: Optional[str]
    created_at: datetime

    class Config:
        from_attributes = True
