<?php

use App\Models\ManagedEnvironment;
use App\Support\Links\RequiredPermissionsLinks;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('builds a tenant-scoped required permissions link without filters', function (): void {
    $tenant = ManagedEnvironment::factory()->create([
        'external_id' => 'tenant-123',
    ]);

    expect(RequiredPermissionsLinks::requiredPermissions($tenant))
        ->toBe(url('/admin/workspaces/'.$tenant->workspace->slug.'/environments/tenant-123/required-permissions'));
});

it('builds a tenant-scoped required permissions link with filters', function (): void {
    $tenant = ManagedEnvironment::factory()->create([
        'external_id' => 'tenant 123',
    ]);

    $url = RequiredPermissionsLinks::requiredPermissions($tenant, [
        'status' => 'all',
        'type' => 'application',
    ]);

    expect($url)->toBe(url('/admin/workspaces/'.$tenant->workspace->slug.'/environments/tenant+123/required-permissions?status=all&type=application'));
});
