<?php

namespace Tests\Feature;

use App\Models\CampaignPerformanceSuggestion;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\Concerns\CreatesAdopsWhaleTables;
use Tests\TestCase;

class BackfillCampaignReviewsCommandTest extends TestCase
{
    use CreatesAdopsWhaleTables;
    use RefreshDatabase;

    public function test_backfill_stores_the_suggestion_and_reports_when_no_analysis_was_written(): void
    {
        $this->travelTo('2026-09-22 12:00:00');
        config([
            'campaign-performance.llm_enabled' => false,
            'campaign-performance.adops_enabled' => true,
        ]);

        $this->createAdopsWhaleTables();
        User::factory()->create();
        $this->seedAdopsCampaign('1201', 'Italy packages', 6.0, 4);

        $this->artisan('campaigns:backfill-reviews', ['--campaign' => '1201'])
            ->expectsOutputToContain('1201 · Italy packages')
            ->expectsOutputToContain('No full recommendation was stored')
            ->expectsOutputToContain('Stored a full recommendation on 0 of 1 campaign(s).')
            ->assertSuccessful();

        $row = CampaignPerformanceSuggestion::query()->first();
        $this->assertNotNull($row);
        $this->assertSame('1201', $row->external_campaign_id);
        $this->assertNull(data_get($row->snapshot, 'review.analysis'));
    }
}
