<?php

namespace App\Classes\Modules\ControllersLogic\FreightForwarder;

use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Classes\Modules\FreightForwarder\DataTransferObjects\FreightForwarderObject;
use App\Classes\Modules\FreightForwarder\Services\UpdatesFreightForwarder;
use App\Classes\ValueObjects\Constants\HttpStatus;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateFreightForwarderLogic
{
    /** @var  UpdatesFreightForwarder */
    private $updatesFreightForwarder;

    /**
     * UpdateFreightForwarderLogic constructor.
     * @param UpdatesFreightForwarder $updatesFreightForwarder
     */
    public function __construct(UpdatesFreightForwarder $updatesFreightForwarder)
    {
        $this->updatesFreightForwarder = $updatesFreightForwarder;
    }


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

        try{
            $object = new FreightForwarderObject($request->input('shipping_rate'), $request->input('overdue_days'), $request->input('markup_percentage'), $request->input('minimum_cbm'));
            return $this->updatesFreightForwarder->execute($forwarderId, $object);
            return new JsonResponse([],HttpStatus::REQUEST_ACCEPTED);

        }catch(\Exception $exception){

            throw new InternalServerErrorException("Failed to update Freight Forwarder because{$exception->getMessage()}");
        }
    }
}