<?php
/**
 * Created by PhpStorm.
 * User: mhmj
 * Date: 17/06/2019
 * Time: 10:18 AM
 */

namespace App\Classes\Modules\ControllersLogic\Orders;


use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Classes\Modules\Orders\DataTransferObjects\ScheduleObject;
use App\Classes\Modules\Orders\Services\UpdateOrderSchedule;
use App\Classes\ValueObjects\Constants\HttpStatus;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateOrderScheduleLogic
{
    /** @var  UpdateOrderSchedule */
    private $updateOrderSchedule;

    /**
     * UpdateOrderScheduleLogic constructor.
     * @param UpdateOrderSchedule $updateOrderSchedule
     */
    public function __construct(UpdateOrderSchedule $updateOrderSchedule)
    {
        $this->updateOrderSchedule = $updateOrderSchedule;
    }

    public function execute(String $scheduleId, Request $request){

        try{
            $scheduleObject = new ScheduleObject($request->input('ETA'), $request->input('ETD'),
                                                $request->input('type'), $request->input('issue_remark'));

            return $this->updateOrderSchedule->execute($scheduleId,$scheduleObject);
            return new JsonResponse([],HttpStatus::REQUEST_ACCEPTED);

        }catch(\Exception $exception){
            throw new InternalServerErrorException("Failed to update schedule because {$exception->getMessage()}");
        }

    }

}