<?php

declare(strict_types=1);

use App\Filament\Pages\EnvironmentDiagnostics;
use App\Models\ManagedEnvironment;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

it('does not use external GUID where internal tenant id is required (diagnostics page loads)', function () {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    // Ensure the tenant has a GUID-like external identifier (this is the tenant route key).
    $tenant->forceFill([
        'external_id' => '00000000-0000-0000-0000-000000000123',
        'managed_environment_id' => '00000000-0000-0000-0000-000000000123',
    ])->save();

    $this->actingAs($user);

    Filament::setTenant($tenant, true);

    Livewire::test(EnvironmentDiagnostics::class)
        ->assertSuccessful();
});
