"""Route schemas."""
from pydantic import BaseModel, field_serializer
from typing import Optional
from datetime import datetime
from uuid import UUID
from app.models.route import RouteStatus


class RouteBase(BaseModel):
    """Base route schema."""
    name: str
    description: Optional[str] = None
    origin_city: str
    destination_city: str
    distance_km: Optional[float] = None
    estimated_duration_minutes: Optional[int] = None
    average_speed_kmh: Optional[float] = None
    status: RouteStatus = RouteStatus.ACTIVE


class RouteCreate(RouteBase):
    """Schema for creating a route."""
    pass


class RouteUpdate(BaseModel):
    """Schema for updating a route."""
    name: Optional[str] = None
    description: Optional[str] = None
    origin_city: Optional[str] = None
    destination_city: Optional[str] = None
    distance_km: Optional[float] = None
    estimated_duration_minutes: Optional[int] = None
    average_speed_kmh: Optional[float] = None
    status: Optional[RouteStatus] = None


class RouteResponse(RouteBase):
    """Schema for route response."""
    id: UUID
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None

    @field_serializer('id')
    def serialize_id(self, value: UUID) -> str:
        return str(value)

    class Config:
        from_attributes = True

