from pydantic import BaseModel, Field
from typing import Optional, Dict, Any
from datetime import datetime
from decimal import Decimal
from uuid import UUID

class AssetCostBase(BaseModel):
    """Alap költség adatok (Frontendről érkező bevitel)."""
    cost_type: str = Field(..., description="fuel, service, fine, insurance, toll, etc.")
    amount_local: Decimal = Field(..., description="A fizetett bruttó összeg helyi devizában")
    currency_local: str = Field("HUF", min_length=3, max_length=3)
    date: datetime = Field(default_factory=datetime.now)
    mileage_at_cost: Optional[int] = Field(None, description="Kilométeróra állása a költség rögzítésekor")
    description: Optional[str] = None
    net_amount_local: Optional[Decimal] = None
    vat_rate: Optional[Decimal] = Field(27.0, description="ÁFA kulcs (pl. 27.0)")
    data: Optional[Dict[str, Any]] = Field(default_factory=dict, description="Extra adatok (pl. helyszín, számlaszám)")

class AssetCostCreate(AssetCostBase):
    """Költség rögzítésekor használt séma."""
    asset_id: UUID
    organization_id: int

class AssetCostResponse(AssetCostBase):
    """Visszatérő adat modell a frontend felé."""
    id: UUID
    asset_id: UUID
    organization_id: int
    driver_id: Optional[int]
    amount_eur: Decimal
    exchange_rate_used: Decimal
    created_at: Optional[datetime] = None

    class Config:
        from_attributes = True