<?php

namespace Kylin\Logistics\Models;

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

/**
 * 路线模型
 *
 * 管理运输路线信息，包括起终点、途经点、总距离、预估时长等。
 *
 * @property string $route_name          路线名称
 * @property string $origin              起点
 * @property string $destination         终点
 * @property float  $total_distance      总距离（公里）
 * @property float  $estimated_duration  预估时长（分钟）
 */
class Route extends Model
{
    protected $table = 'kylin_log_routes';

    protected $fillable = [
        'route_name', 'origin', 'destination', 'waypoints',
        'total_distance', 'estimated_duration', 'origin_lng', 'origin_lat',
        'destination_lng', 'destination_lat',
    ];

    protected $casts = [
        'waypoints' => 'json',
        'total_distance' => 'decimal:10,2',
        'estimated_duration' => 'integer',
        'origin_lng' => 'decimal:12,8',
        'origin_lat' => 'decimal:12,8',
        'destination_lng' => 'decimal:12,8',
        'destination_lat' => 'decimal:12,8',
    ];

    public function dispatches()
    {
        return $this->hasMany(Dispatch::class);
    }
}
