<?php

declare(strict_types=1);

use App\Models\Finding;
use App\Services\Findings\FindingWorkflowService;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('rejects triage from the removed acknowledged status', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    $finding = Finding::factory()->for($tenant)->create([
        'status' => 'acknowledged',
        'acknowledged_at' => now(),
        'acknowledged_by_user_id' => $user->getKey(),
    ]);

    expect(fn () => app(FindingWorkflowService::class)->triage($finding, $tenant, $user))
        ->toThrow(\InvalidArgumentException::class, 'Finding cannot be triaged from the current status.');
});

it('rejects start progress from the removed acknowledged status', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    $finding = Finding::factory()->for($tenant)->create([
        'status' => 'acknowledged',
        'triaged_at' => now()->subMinute(),
        'acknowledged_at' => now(),
        'acknowledged_by_user_id' => $user->getKey(),
    ]);

    expect(fn () => app(FindingWorkflowService::class)->startProgress($finding, $tenant, $user))
        ->toThrow(\InvalidArgumentException::class, 'Finding cannot be moved to in-progress from the current status.');
});
