<?php

namespace Tests\Unit;

use App\Campaigns\CampaignPerformanceSuggestionReplyGuard;
use PHPUnit\Framework\TestCase;

class CampaignPerformanceSuggestionReplyGuardTest extends TestCase
{
    public function test_the_same_stats_keep_the_same_hash(): void
    {
        $guard = new CampaignPerformanceSuggestionReplyGuard;
        $payload = $this->payload(194.29);

        $this->assertSame($guard->hash($payload), $guard->hash($payload));
    }

    public function test_a_changed_stat_changes_the_hash(): void
    {
        $guard = new CampaignPerformanceSuggestionReplyGuard;

        $this->assertNotSame($guard->hash($this->payload(194.29)), $guard->hash($this->payload(200)));
    }

    public function test_prompt_spacing_does_not_change_the_key(): void
    {
        $guard = new CampaignPerformanceSuggestionReplyGuard;

        $this->assertSame(
            $guard->promptKey('Lucos how this campaign works'),
            $guard->promptKey('  LUCOS   how this campaign works '),
        );
    }

    /**
     * @return array<string, mixed>
     */
    private function payload(float $spend): array
    {
        return [
            'from' => '2026-09-09',
            'to' => '2026-10-08',
            'campaign' => [
                'objective' => 'OUTCOME_LEADS',
                'region' => 'US',
                'status' => 'ACTIVE',
            ],
            'delivery' => ['spend' => $spend, 'clicks' => 107],
            'sales' => ['sales' => 4.3],
            'roi' => ['conversions' => 0],
            'health' => 'Needs Optimization',
            'verdict' => [
                'verdict' => 'no_action',
                'recommended_action' => 'NONE',
                'recommended_budget_change_percent' => 0,
            ],
        ];
    }
}
