<?php

namespace Tests\Unit\Services\Keywords;

use App\Services\Keywords\GoogleAdsClientFactory;
use Tests\TestCase;

class GoogleAdsClientFactoryTest extends TestCase
{
    public function test_it_reports_missing_configuration_keys(): void
    {
        config([
            'google-ads.developer_token' => null,
            'google-ads.client_id' => 'client-id',
            'google-ads.client_secret' => null,
            'google-ads.refresh_token' => 'refresh-token',
        ]);

        $missing = (new GoogleAdsClientFactory)->missingConfigurationKeys();

        $this->assertSame([
            'GOOGLE_ADS_DEVELOPER_TOKEN',
            'GOOGLE_ADS_CLIENT_SECRET',
        ], $missing);
    }

    public function test_it_normalizes_customer_ids(): void
    {
        $factory = new GoogleAdsClientFactory;

        $this->assertSame(8039000543, $factory->normalizeCustomerId('8039000543'));
        $this->assertSame(8039000543, $factory->normalizeCustomerId('803-900-0543'));
        $this->assertNull($factory->normalizeCustomerId(''));
    }

    public function test_it_prefers_configured_customer_id_over_login_customer_id(): void
    {
        config([
            'google-ads.customer_id' => '1234567890',
            'google-ads.login_customer_id' => '8039000543',
        ]);

        $this->assertSame('1234567890', (new GoogleAdsClientFactory)->resolveCustomerId());
    }
}
