<?php

namespace Tests\Unit\Services\Keywords;

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

class KeywordIdeaCuratorTest extends TestCase
{
    public function test_it_keeps_only_relevant_keyword_ideas_and_limits_the_list(): void
    {
        config(['google-ads.max_curated_keyword_ideas' => 5]);

        $curated = (new KeywordIdeaCurator)->curate(
            [
                ['term' => "men's levi's 505 jeans", 'avg_monthly_searches' => 14800, 'competition' => 'HIGH'],
                ['term' => "levi's 505 regular fit jeans", 'avg_monthly_searches' => 5400, 'competition' => 'LOW'],
                ['term' => "levi's 505 stretch jeans", 'avg_monthly_searches' => 390, 'competition' => 'HIGH'],
                ['term' => 'zappos levis 505', 'avg_monthly_searches' => 10, 'competition' => 'HIGH'],
                ['term' => 'zara mens stretch jeans', 'avg_monthly_searches' => 10, 'competition' => 'UNSPECIFIED'],
                ['term' => 'best camping tents 2024', 'avg_monthly_searches' => 50000, 'competition' => 'HIGH'],
                ['term' => 'levis 559', 'avg_monthly_searches' => 9900, 'competition' => 'HIGH'],
                ['term' => '513 levis jeans', 'avg_monthly_searches' => 6600, 'competition' => 'HIGH'],
            ],
            [
                "men's levi's 505 jeans",
                'levis 559',
                '513 levis jeans',
            ],
            [
                ['name' => "Men's Levi's® 505™ Regular Fit Stretch Jeans"],
                ['name' => "Men's Levi's® 559™ Relaxed Straight Fit Stretch Jeans"],
                ['name' => "Men's Levi's® 513™ Slim Straight Stretch Jeans"],
            ],
            'Mens',
            'Jeans',
        );

        $this->assertCount(5, $curated);
        $terms = array_column($curated, 'term');
        $this->assertContains("men's levi's 505 jeans", $terms);
        $this->assertContains("levi's 505 regular fit jeans", $terms);
        $this->assertContains('levis 559', $terms);
        $this->assertContains('513 levis jeans', $terms);
        $this->assertNotContains('best camping tents 2024', $terms);
        $this->assertNotContains('zara mens stretch jeans', $terms);
        $this->assertNotContains('zappos levis 505', $terms);
    }
}
