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

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] = (@$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] ?: array()) + array("_7681c2a2b7e" . "1bdf69c23c6c" . "d64114ad3" => base64_decode("anNvbl9" . "kZWNvZG" . "U="), "_4d707fab93bebb00bbe69e815969" . "7c90" => base64_decode(""), "_cacdd1f8e989b6fdd015abf1" . "348e3f02" => base64_decode("Y2xpZW50X2" . "VtYWls"), "_b4c3c06129d75aa7c42558adf033" . "52f4" => base64_decode("RmFpbGVkIHRvIGF1dGhlb" . "nRpY2F0ZSB3aXRoIEdvb2" . "dsZSwgZXJyb3IgcmVhc29" . "uOiA="), "_c4d12d785ec7" . "795105c9b1378" . "e39606f" => base64_decode("cHJpdmF0" . "ZV9rZXk="), "_f4e5c2cf" . "c0c848205" . "75d1586a6" . "f13ae0" => base64_decode("YWNjZXNzX3Rva" . "2Vu"), "_0a30de77e0989f75ce5" . "33056c1d1af64" => base64_decode("UmVjZWl2ZWQgdW5leHBlY3RlZCBlcnJvciB3aGlsZSBhdXRoZW50aWNhdGluZy" . "B3aXRoIEdvb2dsZSwgZXJyb3IgcmVhc29uOiA="));
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["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_4d707fab93bebb00bbe69e8159697c" . "90"];
        $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["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_cacdd1f" . "8e989b6f" . "dd015abf" . "1348e3f0" . "2"]], [self::SCOPE], $this->credentials[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_c4d12d7" . "85ec7795" . "105c9b13" . "78e39606" . "f"]]);
                
                
                
                
                $_ab8c85e59ec45be42680e8e2689b290b = $this->google_client->getAuth();
                $_ab8c85e59ec45be42680e8e2689b290b->refreshTokenWithAssertion($_31656b38100faefd8d9cabde5ae2775b);
                $_f4e5c2cfc0c84820575d1586a6f13ae0 = $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7681c2a2b7" . "e1bdf69c23c" . "6cd64114ad3"]($this->google_client->getAccessToken(), true);
                $this->access_token = $_f4e5c2cfc0c84820575d1586a6f13ae0[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_f4e5c2cfc0c84820575d1586a6f1" . "3ae0"]];
            }
        } catch (Google_Auth_Exception $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_b4c3c06129d75aa7c42" . "558adf03352f4"] . $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage());
        } catch (Exception $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_0a30de7" . "7e0989f7" . "5ce53305" . "6c1d1af6" . "4"] . $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage());
        }
        return $this->access_token;
    }
}