<?php

namespace App\Classes\Modules\Unity\Services;

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

class CreatesContract
{
    private $getAccessToken;

    private $createEntityEndpoint;

    private $contract_hash_id;

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

    public function execute(){

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

        $response = Http::withToken($accessToken)->post($this->createEntityEndpoint,['contract_template_id'=>[$this->contract_hash_id]])->object();

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

    }
}
