<?php

use App\Filament\Resources\OperationRunResource;
use App\Models\OperationRun;
use Illuminate\Support\Facades\Bus;

it('renders Monitoring → Operations index DB-only (no outbound HTTP, no background work)', function () {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    OperationRun::factory()->create([
        'tenant_id' => $tenant->getKey(),
        'type' => 'policy.sync',
        'status' => 'queued',
        'outcome' => 'pending',
        'initiator_name' => 'System',
    ]);

    $this->actingAs($user);

    Bus::fake();

    assertNoOutboundHttp(function () use ($tenant) {
        $this->get(OperationRunResource::getUrl('index', tenant: $tenant))
            ->assertOk()
            ->assertSee('Total Runs (30 days)')
            ->assertSee('Active Runs')
            ->assertSee('Failed/Partial (7 days)')
            ->assertSee('Avg Duration (7 days)')
            ->assertSee('All')
            ->assertSee('Active')
            ->assertSee('Succeeded')
            ->assertSee('Partial')
            ->assertSee('Failed');
    });

    Bus::assertNothingDispatched();
});

it('renders Monitoring → Operations detail DB-only (no outbound HTTP, no background work)', function () {
    [$user, $tenant] = createUserWithTenant(role: 'owner');

    $run = OperationRun::factory()->create([
        'tenant_id' => $tenant->getKey(),
        'type' => 'policy.sync',
        'status' => 'queued',
        'outcome' => 'pending',
        'initiator_name' => 'System',
    ]);

    $this->actingAs($user);

    Bus::fake();

    assertNoOutboundHttp(function () use ($tenant, $run) {
        $this->get(OperationRunResource::getUrl('view', ['record' => $run], tenant: $tenant))
            ->assertOk()
            ->assertSee('Policy sync');
    });

    Bus::assertNothingDispatched();
});
