<?php

namespace Kylin\Logistics\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Kylin\Logistics\Models\GpsLocation;

/**
 * GPS数据上报控制器 - JT/T 808协议适配
 */
class GpsController extends Controller
{
    /**
     * GPS位置上报
     */
    public function report(Request $request): JsonResponse
    {
        $validated = $request->validate([
            'vehicle_id' => 'required|integer|exists:vehicles,id',
            'lng' => 'required|numeric|between:-180,180',
            'lat' => 'required|numeric|between:-90,90',
            'speed' => 'nullable|numeric|min:0',
            'direction' => 'nullable|integer|between:0,360',
            'located_at' => 'required|date',
        ]);

        GpsLocation::create($validated);

        return response()->json([
            'code' => 200,
            'message' => '位置上报成功',
        ]);
    }
}
