<?php

namespace App\Services\Integrations\Sdk;

class Ga4DataApiClientFactory
{
    public function installed(): bool
    {
        return class_exists('Google\\Analytics\\Data\\V1beta\\Client\\BetaAnalyticsDataClient');
    }

    /**
     * This factory intentionally keeps GA4 SDK optional. Our existing GA4 REST sync works
     * with OAuth refresh tokens. The official google/analytics-data client is most useful
     * when service-account credentials or GOOGLE_APPLICATION_CREDENTIALS are configured.
     *
     * @return object
     */
    public function make(array $options = []): object
    {
        if (! $this->installed()) {
            throw new \RuntimeException('google/analytics-data kurulu değil. composer require google/analytics-data çalıştırılmalı.');
        }

        $clientClass = 'Google\\Analytics\\Data\\V1beta\\Client\\BetaAnalyticsDataClient';

        return new $clientClass($options);
    }
}
