<?php

namespace App\Models;

use App\Classes\ValueObjects\Constants\ApprovalStatus;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Schedule extends AbstractModel
{
    use SoftDeletes;

    protected $table = 'schedules';

    protected $dates = ['etd', 'eta'];

    public function owner(): morphTo
    {
        return $this->morphTo();
    }

    public function transport(): BelongsTo
    {
        return $this->BelongsTo(Transport::class, 'transport_id', 'id');
    }

    /**
     * @param $query
     * @return mixed
     */
    public function scopeDispatched($query){
        return $query->where('etd', '<', Carbon::now());
    }

    /**
     * @param $query
     * @return mixed
     */
    public function scopeDropped($query){
        return $query->where('eta', '<', Carbon::now());
    }
}
