<?php

declare(strict_types=1);

use App\Models\ProviderConnection;
use App\Models\ManagedEnvironment;

it('returns 404 for direct provider connection record access by non-tenant members', function (): void {
    $tenantA = ManagedEnvironment::factory()->create();
    $tenantB = ManagedEnvironment::factory()->create([
        'workspace_id' => (int) $tenantA->workspace_id,
    ]);

    [$user] = createUserWithTenant(tenant: $tenantA, role: 'owner');

    $connection = ProviderConnection::factory()->create([
        'workspace_id' => (int) $tenantB->workspace_id,
        'managed_environment_id' => (int) $tenantB->getKey(),
        'provider' => 'microsoft',
    ]);

    $this->actingAs($user)
        ->get('/admin/provider-connections/'.$connection->getKey().'/edit')
        ->assertNotFound();

    $this->actingAs($user)
        ->get('/admin/provider-connections/'.$connection->getKey())
        ->assertNotFound();
});
