<?php

namespace App\Classes\Modules\Unity\Services;

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

class CreatesEntitySignature
{
    private $getAccessToken;

    private $createEntitySignatureEndpoint;

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

    public function execute(string $entity_hash_id){

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

        $response = Http::withToken($accesToken)->post($this->createEntitySignatureEndpoint,['entity_id'=>[$entity_hash_id], 'type'=>'1'])->object();

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

    }
}
