<?php

declare(strict_types=1);

use App\Models\OperationRun;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Route;
use Tests\TestCase;

final class LegacyRoutesReturnNotFoundTest extends TestCase
{
    use RefreshDatabase;

    public function test_returns_404_for_legacy_tenant_scoped_operation_detail_urls(): void
    {
        [$user, $tenant] = createUserWithTenant(role: 'owner');

        $run = OperationRun::factory()->create([
            'workspace_id' => (int) $tenant->workspace_id,
            'managed_environment_id' => (int) $tenant->getKey(),
        ]);

        $this->actingAs($user)
            ->get('/admin/t/'.$tenant->external_id.'/operations/r/'.$run->getKey())
            ->assertNotFound();
    }

    public function test_returns_404_for_the_admin_operations_r_record_legacy_slug_variant(): void
    {
        [$user] = createUserWithTenant(role: 'owner');

        $this->actingAs($user)
            ->get('/admin/operations/r/123')
            ->assertNotFound();
    }

    public function test_does_not_register_legacy_operation_resource_route_names(): void
    {
        $this->assertFalse(Route::has('filament.admin.resources.operations.view'));
        $this->assertFalse(Route::has('filament.admin.resources.operations.index'));
    }
}
