"""Telemetry model for real-time tracking."""
from sqlmodel import SQLModel, Field, Column
from datetime import datetime
from typing import Optional
from uuid import UUID, uuid4
from sqlalchemy import DateTime, func
from enum import Enum

class VehicleStatus(str, Enum):
    ACTIVE = "active"
    OFFLINE = "offline"
    BREAK = "break"

class Telemetry(SQLModel, table=True):
    """Telemetry record for a driver's vehicle."""
    
    __tablename__ = "telemetry"
    
    id: Optional[UUID] = Field(default_factory=uuid4, primary_key=True)
    user_id: UUID = Field(foreign_key="users.id", index=True)
    latitude: float
    longitude: float
    speed: Optional[float] = None
    heading: Optional[float] = None
    status: VehicleStatus = Field(default=VehicleStatus.ACTIVE)
    timestamp: datetime = Field(
        sa_column=Column(DateTime, server_default=func.now(), index=True)
    )

class TelemetryCreate(SQLModel):
    latitude: float
    longitude: float
    speed: Optional[float] = None
    heading: Optional[float] = None
    status: VehicleStatus = VehicleStatus.ACTIVE
