<?php

declare(strict_types=1);

use App\Filament\Resources\RestoreRunResource\Pages\CreateRestoreRun;
use App\Models\ManagedEnvironment;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

describe('Create restore run page authorization', function () {
    it('returns 404 for non-members (deny as not found)', function () {
        $user = User::factory()->create();
        $tenant = ManagedEnvironment::factory()->create();

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

        Livewire::test(CreateRestoreRun::class)
            ->assertStatus(404);
    });

    it('returns 403 for members without tenant manage capability', function () {
        [$user, $tenant] = createUserWithTenant(role: 'operator');

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

        Livewire::test(CreateRestoreRun::class)
            ->assertStatus(403);
    });
});
