<?php

declare(strict_types=1);

use App\Filament\Resources\RestoreRunResource;
use App\Models\BackupSet;
use App\Models\RestoreRun;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('confirms missing relevant restore history on the restore-run list surface', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');
    $this->actingAs($user);

    Filament::setTenant($tenant, true);

    $this->get(RestoreRunResource::getUrl('index', [
        'recovery_posture_reason' => 'no_history',
    ], panel: 'admin', tenant: $tenant))
        ->assertOk()
        ->assertSee('No executed restore history is visible in the latest tenant restore records.')
        ->assertSee('No restore runs');
});

it('keeps recovery-posture list fallback copy readable when a weak restore signal lands on history', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');
    $this->actingAs($user);

    $backupSet = BackupSet::factory()->for($tenant)->create([
        'name' => 'Weak history backup',
    ]);

    RestoreRun::factory()
        ->for($tenant)
        ->for($backupSet)
        ->completedWithFollowUp()
        ->create([
            'completed_at' => now()->subMinutes(10),
        ]);

    Filament::setTenant($tenant, true);

    $this->get(RestoreRunResource::getUrl('index', [
        'recovery_posture_reason' => 'completed_with_follow_up',
    ], panel: 'admin', tenant: $tenant))
        ->assertOk()
        ->assertSee('The dashboard opened restore history because skipped or non-applied work still needs follow-up.')
        ->assertSee('The restore completed, but follow-up remains for skipped or non-applied work.');
});
