<?php

namespace App\Classes\Modules\Unity\Services;

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

class CreatesEntity
{
    private $getAccessToken;

    private $createEntityEndpoint;

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

    public function execute($entity_name){

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

        $response = Http::withToken($accesToken)->post($this->createEntityEndpoint,['name'=>$entity_name])->object();

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

    }
}
