"""Route model."""
from sqlmodel import SQLModel, Field, Column
from datetime import datetime
from typing import Optional
from enum import Enum
from uuid import UUID, uuid4
from sqlalchemy import DateTime, func


class RouteStatus(str, Enum):
    """Route status enumeration."""
    ACTIVE = "active"
    INACTIVE = "inactive"
    MAINTENANCE = "maintenance"


class Route(SQLModel, table=True):
    """Route model representing a bus route."""
    
    __tablename__ = "routes"
    
    id: Optional[UUID] = Field(default_factory=uuid4, primary_key=True)
    name: str = Field(unique=True, index=True)
    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
    created_at: Optional[datetime] = Field(sa_column=Column(DateTime, server_default=func.now()))
    updated_at: Optional[datetime] = Field(sa_column=Column(DateTime, server_default=func.now(), onupdate=func.now()))

