from pydantic import BaseModel, Field
from typing import Optional, List
from enum import Enum
from models import EngineType, HybridType, PowerRatio

class EngineTypeEnum(str, Enum):
    PETROL = "бензиновый"
    DIESEL = "дизельный"
    ELECTRIC = "электрический"

class HybridTypeEnum(str, Enum):
    NONE = "не гибрид"
    HYBRID = "электрогибрид"
    PHEV = "электрогибрид(PHEV)"

class PowerRatioEnum(str, Enum):
    ICE_GREATER = "ДВС > ЭД"
    ELECTRIC_GREATER = "ЭД > ДВС"
    NA = "не применимо"

class CarBase(BaseModel):
    image: Optional[str] = None
    name: str
    price: float
    base_price: float
    country_of_origin: str
    year: int
    drive_type: str
    mileage: Optional[int] = None
    engine_capacity: Optional[float] = None
    engine_power: Optional[int] = None
    engine_type: EngineTypeEnum
    electric_motor_power: Optional[int] = None
    hybrid_type: HybridTypeEnum = HybridTypeEnum.NONE
    power_ratio: PowerRatioEnum = PowerRatioEnum.NA

class CarCreate(CarBase):
    pass

class CarUpdate(BaseModel):
    image: Optional[str] = None
    name: Optional[str] = None
    price: Optional[float] = None
    base_price: Optional[float] = None
    country_of_origin: Optional[str] = None
    year: Optional[int] = None
    drive_type: Optional[str] = None
    mileage: Optional[int] = None
    engine_capacity: Optional[float] = None
    engine_power: Optional[int] = None
    engine_type: Optional[EngineTypeEnum] = None
    electric_motor_power: Optional[int] = None
    hybrid_type: Optional[HybridTypeEnum] = None
    power_ratio: Optional[PowerRatioEnum] = None

class Car(CarBase):
    id: int

    class Config:
        from_attributes = True

class CarResponse(BaseModel):
    car: Car

class CarsResponse(BaseModel):
    cars: List[Car]
    total: int 
