<?php

declare(strict_types=1);

use App\Models\OperationRun;
use App\Support\Workspaces\WorkspaceContext;
use Filament\Facades\Filament;
use Illuminate\Support\Facades\Bus;

it('keeps operations list and detail rendering DB-only', function (): void {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    $run = OperationRun::factory()->create([
        'managed_environment_id' => (int) $tenant->getKey(),
        'workspace_id' => (int) $tenant->workspace_id,
        'type' => 'restore.execute',
        'status' => 'completed',
        'outcome' => 'succeeded',
        'initiator_name' => 'System',
    ]);

    $this->actingAs($user);
    Bus::fake();
    Filament::setTenant(null, true);

    assertNoOutboundHttp(function () use ($tenant, $run): void {
        $this->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
            ->get(\App\Support\OperationRunLinks::index())
            ->assertOk()
            ->assertSee('All');

        $this->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
            ->get(\App\Support\OperationRunLinks::tenantlessView($run))
            ->assertOk()
            ->assertSee(\App\Support\OperationRunLinks::identifier($run));
    });

    Bus::assertNothingDispatched();
});
