<?php

declare(strict_types=1);

use App\Services\Operations\TargetScopeConcurrencyLimiter;

it('defaults per-target scope concurrency to 1', function (): void {
    config()->set('tenantpilot.bulk_operations.concurrency.per_target_scope_max', 1);

    $tenantId = 123;

    $limiter = app(TargetScopeConcurrencyLimiter::class);

    $lockA = $limiter->acquireSlot($tenantId, ['entra_tenant_id' => '00000000-0000-0000-0000-000000000001']);
    expect($lockA)->not->toBeNull();

    $lockB = $limiter->acquireSlot($tenantId, ['entra_tenant_id' => '00000000-0000-0000-0000-000000000001']);
    expect($lockB)->toBeNull();

    $lockOtherScope = $limiter->acquireSlot($tenantId, ['entra_tenant_id' => '00000000-0000-0000-0000-000000000002']);
    expect($lockOtherScope)->not->toBeNull();

    $lockA?->release();
    $lockOtherScope?->release();
})->group('ops-ux');
