<?php

namespace App\Classes\Modules\ControllersLogic\FreightForwarder;

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

class UpdateCustomerRelationLogic
{
    /** @var  UpdatesCustomerRelation */
    private $updatesCustomerRelation;

    /**
     * UpdateCustomerRelationLogic constructor.
     * @param UpdatesCustomerRelation $updatesCustomerRelation
     */
    public function __construct(UpdatesCustomerRelation $updatesCustomerRelation)
    {
        $this->updatesCustomerRelation = $updatesCustomerRelation;
    }

    public function execute(int $companyId, Request $request){

        try{
            $object = new CustomerRelationObject(1, $companyId, $request->input('customer_rate'), $request->input('wave'));
            return $this->updatesCustomerRelation->execute($object);
            return new JsonResponse([], HttpStatus::REQUEST_ACCEPTED);

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