<?php

declare(strict_types=1);

use App\Filament\Resources\FindingResource\Pages\ListFindings;
use App\Models\Finding;
use App\Models\OperationRun;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

it('removes the tenant findings lifecycle backfill header action without removing canonical workflow actions', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    $finding = Finding::factory()->for($tenant)->create([
        'status' => Finding::STATUS_NEW,
    ]);

    $this->actingAs($user);
    Filament::setTenant($tenant, true);

    Livewire::test(ListFindings::class)
        ->assertActionDoesNotExist('backfill_lifecycle')
        ->assertActionExists('triage_all_matching')
        ->assertTableActionVisible('triage', $finding)
        ->assertTableActionVisible('assign', $finding)
        ->assertTableActionVisible('resolve', $finding)
        ->assertTableActionVisible('request_exception', $finding);

    expect(OperationRun::query()->where('type', 'findings.lifecycle.backfill')->exists())->toBeFalse();
});
