<?php

namespace App\Classes\Modules\Orders\Services\Attachments;


use App\Classes\Modules\Orders\DataTransferObjects\ScheduleObject;
use App\Models\Schedule;

class UpdatesSchedule
{

    /** @var Schedule */
    private $repository;

    /**
     * UpdatesSchedule constructor.
     * @param Schedule $repository
     */
    public function __construct(Schedule $repository)
    {
        $this->repository = $repository;
    }


    public function execute(int $arrangementId, ScheduleObject $schedule){

        $this->repository->where('arrangement_id', $arrangementId)->where('type', $schedule->getType())->where('status', 0)
            ->update(['status' => 2, 'issue_remark' => $schedule->getIssue()]);

        $this->repository->arrangement_id = $arrangementId;
        $this->repository->type = $schedule->getType();
        $this->repository->ETA = $schedule->getETA();
        $this->repository->ETD = $schedule->getETD();

        $this->repository->save();

    }


}