<?php

namespace App\Classes\Modules\Unity\Services;

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

class ActivatesContract
{
    private $getAccessToken;

    private $activateEntityEndpoint;

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

    public function execute($contract_hash_id){

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

        $this->activateEntityEndpoint = str_replace('{hash}',$contract_hash_id,$this->activateEntityEndpoint);

        $response = Http::withToken($accessToken)->put($this->activateEntityEndpoint)->object();

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

    }
}
