<?php

namespace Tests\Unit;

use App\Campaigns\PerformanceVerdict;
use App\Campaigns\PerformanceVerdictCombiner;
use Tests\TestCase;

class PerformanceVerdictCombinerTest extends TestCase
{
    public function test_it_escalates_to_stop_when_three_hour_and_seven_day_both_pause(): void
    {
        $result = (new PerformanceVerdictCombiner)->final([
            '3h' => ['verdict' => 'pause', 'reason' => '3h bad'],
            '5h' => ['verdict' => 'continue', 'reason' => '5h ok'],
            '7h' => ['verdict' => 'continue', 'reason' => '7h ok'],
            '3d' => ['verdict' => 'continue', 'reason' => '3d ok'],
            '7d' => ['verdict' => 'pause', 'reason' => '7d bad'],
        ]);

        $this->assertSame(PerformanceVerdict::Stop, $result['verdict']);
    }

    public function test_it_prefers_action_required_over_pause(): void
    {
        $result = (new PerformanceVerdictCombiner)->final([
            '3h' => ['verdict' => 'action_required', 'reason' => 'sync failed'],
            '7d' => ['verdict' => 'pause', 'reason' => '7d bad'],
        ]);

        $this->assertSame(PerformanceVerdict::ActionRequired, $result['verdict']);
    }

    public function test_hourly_combiner_only_uses_intraday_windows(): void
    {
        $result = (new PerformanceVerdictCombiner)->hourly([
            '3h' => ['verdict' => 'pause', 'reason' => '3h bad'],
            '5h' => ['verdict' => 'pause', 'reason' => '5h bad'],
            '7h' => ['verdict' => 'continue', 'reason' => '7h ok'],
        ]);

        $this->assertNotNull($result);
        $this->assertSame(PerformanceVerdict::Stop, $result['verdict']);
        $this->assertStringStartsWith('Hourly check:', $result['reason']);
    }
}
