<?php

declare(strict_types=1);

use App\Support\OperationalControls\OperationalControlCatalog;

it('exposes only active runtime controls in the bounded control catalog', function (): void {
    $catalog = app(OperationalControlCatalog::class);

    expect($catalog->keys())->toBe(['restore.execute', 'promotion.execute', 'ai.execution'])
        ->and($catalog->definition('restore.execute'))->toMatchArray([
        'key' => 'restore.execute',
        'label' => 'Restore execution',
        'supported_scopes' => ['global', 'workspace'],
        'operation_types' => ['restore.execute'],
    ])
        ->and($catalog->definition('promotion.execute'))->toMatchArray([
        'key' => 'promotion.execute',
        'label' => 'Promotion execution',
        'supported_scopes' => ['global', 'workspace'],
        'operation_types' => ['promotion.execute'],
    ])
        ->and($catalog->definition('ai.execution'))->toMatchArray([
        'key' => 'ai.execution',
        'label' => 'AI execution',
        'supported_scopes' => ['global'],
        'operation_types' => ['ai.execution'],
    ]);
});

it('rejects removed or unknown control keys', function (): void {
    $catalog = app(OperationalControlCatalog::class);

    expect(fn (): array => $catalog->definition('findings.lifecycle.backfill'))
        ->toThrow(\InvalidArgumentException::class)
        ->and(fn (): array => $catalog->definition('environment.review.compose'))
        ->toThrow(\InvalidArgumentException::class);
});