<?php

namespace Kylin\Logistics\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Kylin\Logistics\Enums\DispatchStatus;

/**
 * 调度模型
 *
 * 管理运单调度信息，关联运单、车辆、司机、路线。
 *
 * @property string $dispatch_time    调度时间
 * @property string $departure_time   出发时间
 * @property string $arrival_time     到达时间
 * @property string $status           调度状态
 */
class Dispatch extends Model
{
    protected $table = 'kylin_log_dispatches';

    protected $fillable = [
        'waybill_id', 'vehicle_id', 'driver_id', 'route_id',
        'dispatch_time', 'departure_time', 'arrival_time', 'status',
    ];

    protected $casts = [
        'status' => DispatchStatus::class,
        'dispatch_time' => 'datetime',
        'departure_time' => 'datetime',
        'arrival_time' => 'datetime',
    ];

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

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

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

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