from pydantic import BaseModel, ConfigDict
from typing import Optional, List
from datetime import date, datetime
from app.models.expense import ExpenseCategory

# --- Vehicle Schemas ---
class VehicleBase(BaseModel):
    license_plate: str
    make: str
    model: str
    year: int
    fuel_type: Optional[str] = None
    vin: Optional[str] = None
    initial_odometer: int = 0
    mot_expiry_date: Optional[date] = None
    insurance_expiry_date: Optional[date] = None

class VehicleCreate(VehicleBase):
    pass

class VehicleResponse(VehicleBase):
    id: int
    current_odometer: int
    created_at: datetime
    model_config = ConfigDict(from_attributes=True)

# --- Event / Expense Schemas ---
class EventBase(BaseModel):
    event_type: ExpenseCategory
    date: date
    odometer_value: int
    cost_amount: int
    description: Optional[str] = None
    is_diy: bool = False
    
    # Ad-Hoc Provider mező: Ha stringet kapunk, a service megkeresi vagy létrehozza
    provider_name: Optional[str] = None 
    provider_id: Optional[int] = None # Ha már ismert ID-t küldünk

class EventCreate(EventBase):
    pass

class EventResponse(EventBase):
    id: int
    vehicle_id: int
    odometer_anomaly: bool
    service_provider_id: Optional[int]
    image_paths: Optional[List[str]] = []
    
    model_config = ConfigDict(from_attributes=True)

class TCOStats(BaseModel):
    vehicle_id: int
    total_cost: int
    breakdown: dict[str, int] # Kategóriánkénti bontás
    cost_per_km: Optional[float] = 0.0