<?php

namespace Kylin\Logistics\Models;

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

/**
 * 司机模型
 *
 * 管理驾驶员信息，包括驾驶证、从业资格证、绑定车辆等。
 *
 * @property string $license_no          驾驶证号
 * @property string $license_type        驾驶证类型
 * @property string $license_expire      驾驶证有效期
 * @property string $qualification_no    从业资格证号
 */
class Driver extends Model
{
    protected $table = 'kylin_log_drivers';

    protected $fillable = [
        'user_id', 'vehicle_id', 'license_no', 'license_type',
        'license_expire', 'qualification_no', 'qualification_expire',
    ];

    protected $casts = [
        'license_expire' => 'date',
        'qualification_expire' => 'date',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(config('auth.providers.users.model'), 'user_id');
    }

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

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