from fastapi import APIRouter

from core.schemas import GpsPoint

router = APIRouter(prefix="/gps", tags=["iot"])
GPS_STORE: dict[str, list[tuple[float, float]]] = {}


@router.post("/track")
def track(point: GpsPoint) -> dict:
    GPS_STORE.setdefault(point.vehicle_id, []).append((point.lat, point.lon))
    GPS_STORE[point.vehicle_id] = GPS_STORE[point.vehicle_id][-500:]
    return {"success": True, "vehicle_id": point.vehicle_id, "count": len(GPS_STORE[point.vehicle_id])}
