<?php

namespace App\Classes\Modules\Unity\Services;

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

class GetContractObligations
{
    private $getContractObligationsEndpoint;

    private $getAccessToken;

    public function __construct(GetAccessToken $getAccessToken)
    {
        $this->getContractObligationsEndpoint = Config::get('unity.url').Config::get('unity.get_ob_endpoint');

        $this->getAccessToken = $getAccessToken;
    }

    public function execute(){

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

        $response = Http::withToken($accesToken)->get($this->getContractObligationsEndpoint)->object();

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

    }
}
