<?php

namespace Tests\Unit\AdOps;

use App\Services\AdOps\CreativeCampaignTypes;
use PHPUnit\Framework\TestCase;

/**
 * The compatibility map is the one place two copies had already drifted — the
 * API keys Swicki as `adx`, the linked-campaigns picker keyed it `swicki`.
 */
final class CreativeCampaignTypesTest extends TestCase
{
    public function testTheApiKeyAndTheUiLabelResolveToTheSameRule(): void
    {
        $this->assertSame('adx', CreativeCampaignTypes::normalize('swicki'));
        $this->assertSame('adx', CreativeCampaignTypes::normalize('Swicki'));
        $this->assertSame(['text'], CreativeCampaignTypes::creativeTypesFor('swicki'));
        $this->assertSame(['text'], CreativeCampaignTypes::creativeTypesFor('adx'));
    }

    public function testLabelSpellingsFromTheUiResolve(): void
    {
        $this->assertSame('text-pop', CreativeCampaignTypes::normalize('Text Pop'));
        $this->assertSame('text-search', CreativeCampaignTypes::normalize('Text Search'));
    }

    public function testTheDocumentedPairings(): void
    {
        $this->assertTrue(CreativeCampaignTypes::allows('display', 'image'));
        $this->assertTrue(CreativeCampaignTypes::allows('display', 'script'));
        $this->assertFalse(CreativeCampaignTypes::allows('display', 'text'));
        $this->assertTrue(CreativeCampaignTypes::allows('native', 'native'));
        $this->assertFalse(CreativeCampaignTypes::allows('native', 'image'));
        $this->assertTrue(CreativeCampaignTypes::allows('text-search', 'text'));
        $this->assertTrue(CreativeCampaignTypes::allows('text-search', 'instl'));
        $this->assertFalse(CreativeCampaignTypes::allows('text-search', 'image'));
        // Swicki takes text only — instl is absent from the API's list.
        $this->assertFalse(CreativeCampaignTypes::allows('adx', 'instl'));
    }

    public function testAnUnjudgeableCampaignTypeIsAllowed(): void
    {
        // 3,030 live links sit on campaign_type/campaign_mode combinations with no
        // row in campaign_type, and video is disabled in the API's map. Treating
        // "no opinion" as "not allowed" would refuse them all.
        $this->assertSame([], CreativeCampaignTypes::creativeTypesFor('video'));
        $this->assertTrue(CreativeCampaignTypes::allows('video', 'video'));
        $this->assertTrue(CreativeCampaignTypes::allows('', 'image'));
        $this->assertTrue(CreativeCampaignTypes::allows(null, 'image'));
    }

    public function testCaseAndPaddingDoNotMatter(): void
    {
        $this->assertTrue(CreativeCampaignTypes::allows(' Display ', ' IMAGE '));
    }
}
