<?php

namespace Kylin\Logistics\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * GPS 定位模型
 *
 * 存储车辆实时 GPS 位置数据，包括经纬度、速度、方向。
 *
 * @property float  $lng        经度
 * @property float  $lat        纬度
 * @property float  $speed      速度
 * @property float  $direction  方向
 * @property string $located_at 定位时间
 */
class GpsLocation extends Model
{
    public $timestamps = false;

    protected $table = 'kylin_log_gps_locations';

    protected $fillable = [
        'vehicle_id', 'lng', 'lat', 'speed', 'direction', 'located_at',
    ];

    protected $casts = [
        'lng' => 'decimal:12,8',
        'lat' => 'decimal:12,8',
        'speed' => 'decimal:5,1',
        'direction' => 'integer',
        'located_at' => 'datetime',
    ];

    public function vehicle(): BelongsTo
    {
        return $this->belongsTo(Vehicle::class);
    }
}
