<?php

declare(strict_types=1);

use App\Services\Operations\OperationLifecyclePolicyValidator;
use App\Support\Operations\OperationLifecyclePolicy;

it('exposes the exact covered v1 lifecycle operation set', function (): void {
    $types = app(OperationLifecyclePolicy::class)->coveredTypeNames();

    expect($types)->toBe([
        'baseline.capture',
        'baseline.compare',
        'inventory.sync',
        'policy.sync',
        'directory.groups.sync',
        'directory.role_definitions.sync',
        'backup_set.update',
        'backup.schedule.execute',
        'restore.execute',
        'promotion.execute',
        'environment.review_pack.generate',
        'environment.review.compose',
        'tenant.evidence.snapshot.generate',
    ]);
});

it('requires direct failed-job bridges for lifecycle policy entries that declare them', function (): void {
    $validator = app(OperationLifecyclePolicyValidator::class);

    expect($validator->jobUsesDirectFailedBridge('baseline.capture'))->toBeTrue()
        ->and($validator->jobUsesDirectFailedBridge('baseline.compare'))->toBeTrue()
        ->and($validator->jobUsesDirectFailedBridge('inventory.sync'))->toBeTrue()
        ->and($validator->jobUsesDirectFailedBridge('policy.sync'))->toBeTrue()
        ->and($validator->jobUsesDirectFailedBridge('environment.review.compose'))->toBeTrue()
        ->and($validator->jobUsesDirectFailedBridge('backup.schedule.execute'))->toBeFalse();
});

it('requires explicit timeout and fail-on-timeout declarations for covered jobs', function (): void {
    $validator = app(OperationLifecyclePolicyValidator::class);

    expect($validator->jobTimeoutSeconds('baseline.capture'))->toBe(300)
        ->and($validator->jobFailsOnTimeout('baseline.capture'))->toBeTrue()
        ->and($validator->jobTimeoutSeconds('backup_set.update'))->toBe(240)
        ->and($validator->jobFailsOnTimeout('backup_set.update'))->toBeTrue()
        ->and($validator->jobTimeoutSeconds('restore.execute'))->toBe(420)
        ->and($validator->jobTimeoutSeconds('promotion.execute'))->toBe(420)
        ->and($validator->jobFailsOnTimeout('restore.execute'))->toBeTrue();
});
