<?php

namespace App\Classes\Modules\Unity\Services;

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

class CreatesContractEntity
{
    private $getAccessToken;

    private $createContractEntityEndpoint;

    private $contract_hash_id;

    public function __construct(GetAccessToken $getAccessToken)
    {
        $this->createContractEntityEndpoint = Config::get('unity.url').Config::get('unity.endpoint.create_contract_entity');
        $this->getAccessToken = $getAccessToken;
        $this->contract_hash_id = Config::get('unity.contract_template_hash_id');
    }

    public function execute(string $new_contract_id, string $entity_hash_ids){

        $accesToken=$this->getAccessToken->execute();
        $response = Http::withToken($accesToken)->post($this->createContractEntityEndpoint,['contract_id'=>[$new_contract_id],'entity_id'=>$entity_hash_ids])->object();
        return (isset($response->data)) ? $response->data : null;

    }
}
