<?php

namespace App\Classes\Modules\Unity\Services;

use Config;
use Illuminate\Support\Facades\Http;
use App\Classes\Modules\Unity\Services\GetAccessToken;

class UpdatesContractObligation
{
    private $getAccessToken;

    private $updateContractStatusEndpoint;

    public function __construct(GetAccessToken $getAccessToken)
    {
        $this->updateContractStatusEndpoint = Config::get('unity.url').Config::get('unity.endpoint.update_obligation_status');
        $this->getAccessToken = $getAccessToken;
    }

    public function execute($contract_entity_signature, $obligation_hash_id){

        $accessToken=$this->getAccessToken->execute();

        $this->updateContractStatusEndpoint = str_replace('{hash}', $obligation_hash_id, $this->updateContractStatusEndpoint);

        $response = Http::withToken($accessToken)->put($this->updateContractStatusEndpoint,['entity_signature_id'=>$contract_entity_signature])->object();

        return (isset($response->data)) ? $response->data : null;

    }
}
