<?php

namespace Tests\Unit\Services\Keywords;

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

class HeuristicKeywordMatcherTest extends TestCase
{
    public function test_it_matches_keywords_using_token_overlap(): void
    {
        $match = (new HeuristicKeywordMatcher)->match(
            'Ergonomic Mesh Office Chair',
            [
                [
                    'term' => 'office chair',
                    'avg_monthly_searches' => 201000,
                    'competition' => 'HIGH',
                ],
                [
                    'term' => 'camping tent',
                    'avg_monthly_searches' => 50000,
                    'competition' => 'MEDIUM',
                ],
            ],
        );

        $this->assertSame('office chair', $match['term'] ?? null);
    }

    public function test_it_returns_null_when_no_keyword_overlaps(): void
    {
        $match = (new HeuristicKeywordMatcher)->match(
            'Mystery Gadget',
            [
                [
                    'term' => 'camping tent',
                    'avg_monthly_searches' => 50000,
                    'competition' => 'MEDIUM',
                ],
            ],
        );

        $this->assertNull($match);
    }
}
