<?php

declare(strict_types=1);

use App\Support\Badges\BadgeCatalog;
use App\Support\Badges\BadgeDomain;
use App\Support\Inventory\InventoryPolicyTypeMeta;
use Illuminate\Support\Facades\App;

it('maps policy provider presence values to canonical badge semantics', function (): void {
    App::setLocale('en');

    $active = BadgeCatalog::spec(BadgeDomain::PolicyProviderPresence, 'active');
    expect($active->label)->toBe(__('localization.policy.badges.active'));
    expect($active->color)->toBe('success');

    $ignored = BadgeCatalog::spec(BadgeDomain::PolicyProviderPresence, 'ignored_locally');
    expect($ignored->label)->toBe(__('localization.policy.badges.ignored_locally'));
    expect($ignored->color)->toBe('warning');

    $missing = BadgeCatalog::spec(BadgeDomain::PolicyProviderPresence, 'provider_missing');
    expect($missing->label)->toBe(__('localization.policy.badges.source_unavailable'));
    expect($missing->color)->toBe('warning');

    $combined = BadgeCatalog::spec(BadgeDomain::PolicyProviderPresence, 'ignored_locally_provider_missing');
    expect($combined->label)->toBe(__('localization.policy.badges.ignored_source_unavailable'));
    expect($combined->color)->toBe('danger');
});

it('maps policy snapshot mode values to canonical badge semantics', function (): void {
    App::setLocale('en');

    $full = BadgeCatalog::spec(BadgeDomain::PolicySnapshotMode, 'full');
    expect($full->label)->toBe(__('localization.policy.versions.snapshot_mode_full'));
    expect($full->color)->toBe('success');

    $metadataOnly = BadgeCatalog::spec(BadgeDomain::PolicySnapshotMode, 'metadata_only');
    expect($metadataOnly->label)->toBe(__('localization.policy.versions.snapshot_mode_metadata_only'));
    expect($metadataOnly->color)->toBe('warning');
});

it('maps policy restore mode values to canonical badge semantics', function (): void {
    $enabled = BadgeCatalog::spec(BadgeDomain::PolicyRestoreMode, 'enabled');
    expect($enabled->label)->toBe('Enabled');
    expect($enabled->color)->toBe('success');

    $previewOnly = BadgeCatalog::spec(BadgeDomain::PolicyRestoreMode, 'preview-only');
    expect($previewOnly->label)->toBe('Preview only');
    expect($previewOnly->color)->toBe('warning');
});

it('maps policy risk values to canonical badge semantics', function (): void {
    $low = BadgeCatalog::spec(BadgeDomain::PolicyRisk, 'low');
    expect($low->label)->toBe('Low');
    expect($low->color)->toBe('gray');

    $mediumHigh = BadgeCatalog::spec(BadgeDomain::PolicyRisk, 'medium-high');
    expect($mediumHigh->label)->toBe('Medium-high');
    expect($mediumHigh->color)->toBe('danger');
});

it('maps ignored-at presence to canonical badge semantics', function (): void {
    $notIgnored = BadgeCatalog::spec(BadgeDomain::IgnoredAt, null);
    expect($notIgnored->label)->toBe('No');
    expect($notIgnored->color)->toBe('gray');

    $ignored = BadgeCatalog::spec(BadgeDomain::IgnoredAt, '2026-01-01T00:00:00Z');
    expect($ignored->label)->toBe('Yes');
    expect($ignored->color)->toBe('warning');
});

it('maps RBAC foundation restore modes to preview-only metadata', function (): void {
    expect(InventoryPolicyTypeMeta::restoreMode('intuneRoleDefinition'))->toBe('preview-only');
    expect(InventoryPolicyTypeMeta::restoreMode('intuneRoleAssignment'))->toBe('preview-only');
});
