<?php
namespace Claromentis\Core\Ai\Adapters\Vertex\Requests;

$GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"] = (@$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"] ?: array()) + array("_cacdd1f8" . "e989b6fdd" . "015abf134" . "8e3f02" => base64_decode("Y2xpZW5" . "0X2VtYW" . "ls"), "_7681c2a2b7e1bdf" . "69c23c6cd64114ad" . "3" => base64_decode("anNvbl" . "9kZWNv" . "ZGU="), "_c4d12d785ec7795105c9b1378" . "e39606f" => base64_decode("cHJp" . "dmF0" . "ZV9r" . "ZXk="), "_f4e5c2cfc0c84820575d15" . "86a6f13ae0" => base64_decode("YWNjZXNzX3Rva2" . "Vu"), "_4d707fab93bebb00bbe69e8" . "159697c90" => base64_decode(""), "_0a30de77e0989f75ce533056" . "c1d1af64" => base64_decode("UmVjZWl2ZWQgdW5leHBlY3RlZCB" . "lcnJvciB3aGlsZSBhdXRoZW50aW" . "NhdGluZyB3aXRoIEdvb2dsZSwgZ" . "XJyb3IgcmVhc29uOiA="), "_b4c3c06129d7" . "5aa7c42558adf" . "03352f4" => base64_decode("RmFpbGVkIHRvIGF1dGhlbnRpY2F" . "0ZSB3aXRoIEdvb2dsZSwgZXJyb3" . "IgcmVhc29uOiA="));
use Exception;
use Google_Auth_AssertionCredentials;
use Google_Auth_Exception;
use Google_Client;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;






class VertexAiClientAuthentication implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    
    
    
    
    private const SCOPE = 'https://www.googleapis.com/auth/cloud-platform';
    
    
    
    
    private array $credentials;
    
    
    
    
    private ?string $access_token;
    
    
    
    
    private Google_Client $google_client;
    
    
    
    
    
    
    
    public function __construct(array $_31656b38100faefd8d9cabde5ae2775b, LoggerInterface $logger = null)
    {
        $this->credentials = $_31656b38100faefd8d9cabde5ae2775b;
        $this->access_token = $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_4d707fab9" . "3bebb00bbe" . "69e8159697" . "c90"];
        $this->google_client = new Google_Client();
        $this->logger = $logger ?? new NullLogger();
    }
    
    
    
    
    
    
    
    
    public function getAccessToken() : string
    {
        try {
            if ($this->google_client->isAccessTokenExpired()) {
                $_31656b38100faefd8d9cabde5ae2775b = new Google_Auth_AssertionCredentials($this->credentials[$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_cacdd1f8" . "e989b6fdd" . "015abf134" . "8e3f02"]], [self::SCOPE], $this->credentials[$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_c4d12d785ec77" . "95105c9b1378e3" . "9606f"]]);
                
                
                
                
                $_ab8c85e59ec45be42680e8e2689b290b = $this->google_client->getAuth();
                $_ab8c85e59ec45be42680e8e2689b290b->refreshTokenWithAssertion($_31656b38100faefd8d9cabde5ae2775b);
                $_f4e5c2cfc0c84820575d1586a6f13ae0 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_7681c2a2b7e1bd" . "f69c23c6cd64114" . "ad3"]($this->google_client->getAccessToken(), true);
                $this->access_token = $_f4e5c2cfc0c84820575d1586a6f13ae0[$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_f4e5c2cfc0c84820575d15" . "86a6f13ae0"]];
            }
        } catch (Google_Auth_Exception $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_b4c3c06129d75aa7c42558adf0" . "3352f4"] . $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage());
        } catch (Exception $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_0a30de77e0989f75ce" . "533056c1d1af64"] . $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage());
        }
        return $this->access_token;
    }
}