<?php

declare(strict_types=1);

use App\Support\Governance\PlatformVocabularyGlossary;

it('publishes canonical term inventory with boundary classifications and retirement metadata', function (): void {
    $glossary = app(PlatformVocabularyGlossary::class);

    expect($glossary->canonicalTerms())
        ->toContain('governed_subject', 'operation_type', 'policy_type')
        ->and($glossary->term('governed_subject')?->boundaryClassification)->toBe(PlatformVocabularyGlossary::BOUNDARY_PLATFORM_CORE)
        ->and($glossary->term('governed_subject')?->legacyAliases)->toContain('policy_type')
        ->and($glossary->term('governed_subject')?->aliasRetirementPath)->toContain('policy_type');
});

it('prefers exact Intune-specific terms while still resolving platform aliases by context', function (): void {
    $glossary = app(PlatformVocabularyGlossary::class);

    expect($glossary->term('policy_type')?->boundaryClassification)->toBe(PlatformVocabularyGlossary::BOUNDARY_INTUNE_SPECIFIC)
        ->and($glossary->resolveAlias('policy_type', 'compare')?->termKey)->toBe('governed_subject')
        ->and($glossary->resolveAlias('policy_type', 'intune_adapter'))->toBeNull();
});

it('publishes contributor-facing registry, alias, and reason-namespace inventories', function (): void {
    $glossary = app(PlatformVocabularyGlossary::class);
    $termInventory = $glossary->termInventory();
    $aliasInventory = $glossary->aliasRetirementInventory();
    $registryInventory = $glossary->registryInventory();
    $reasonNamespaceInventory = $glossary->reasonNamespaceInventory();

    expect($termInventory['operation_type']['boundary_classification'] ?? null)->toBe(PlatformVocabularyGlossary::BOUNDARY_PLATFORM_CORE)
        ->and($aliasInventory['governed_subject']['canonical_name'] ?? null)->toBe('governed_subject')
        ->and($aliasInventory['governed_subject']['legacy_aliases'] ?? [])->toContain('policy_type')
        ->and($registryInventory['operation_catalog']['canonical_nouns'] ?? [])->toContain('operation_type')
        ->and($reasonNamespaceInventory['governance.baseline_compare']['boundary_classification'] ?? null)->toBe(PlatformVocabularyGlossary::BOUNDARY_CROSS_DOMAIN_GOVERNANCE)
        ->and($reasonNamespaceInventory['rbac.intune']['boundary_classification'] ?? null)->toBe(PlatformVocabularyGlossary::BOUNDARY_INTUNE_SPECIFIC);
});