<?php
/**
 * Created by PhpStorm.
 * User: mhmj
 * Date: 18/07/2019
 * Time: 4:45 PM
 */

namespace App\Classes\Modules\ControllersLogic\FreightForwarder;


use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Classes\Modules\FreightForwarder\DataTransferObjects\ServiceObject;
use App\Classes\Modules\FreightForwarder\Services\UpdatesServiceFees;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateServiceFeesLogic
{
    /** @var  UpdatesServiceFees */
    private $updatesServiceFees;

    /**
     * UpdateServiceFeesLogic constructor.
     * @param UpdatesServiceFees $updatesServiceFees
     */
    public function __construct(UpdatesServiceFees $updatesServiceFees)
    {
        $this->updatesServiceFees = $updatesServiceFees;
    }


    public function execute(int $forwarderId, Request $request){
        try{
            $object = new ServiceObject($request->input('type'), $forwarderId, $request->input('name'), $request->input('description'), $request->input('cost'));
            return $this->updatesServiceFees->execute($object, $request->input('id'));
            return new JsonResponse([],HttpStatus::REQUEST_ACCEPTED);

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

    }

}