<?php

declare(strict_types=1);

use App\Services\Baselines\SnapshotRendering\Renderers\DeviceComplianceSnapshotTypeRenderer;
use App\Services\Baselines\SnapshotRendering\Renderers\FallbackSnapshotTypeRenderer;
use App\Services\Baselines\SnapshotRendering\Renderers\IntuneRoleDefinitionSnapshotTypeRenderer;
use App\Services\Baselines\SnapshotRendering\SnapshotTypeRendererRegistry;

it('resolves dedicated renderers before the fallback renderer', function (): void {
    $fallback = new FallbackSnapshotTypeRenderer;
    $registry = new SnapshotTypeRendererRegistry(
        renderers: [
            new IntuneRoleDefinitionSnapshotTypeRenderer,
            new DeviceComplianceSnapshotTypeRenderer,
        ],
        fallbackRenderer: $fallback,
    );

    expect($registry->rendererFor('intuneRoleDefinition'))->toBeInstanceOf(IntuneRoleDefinitionSnapshotTypeRenderer::class)
        ->and($registry->rendererFor('deviceCompliancePolicy'))->toBeInstanceOf(DeviceComplianceSnapshotTypeRenderer::class)
        ->and($registry->usesFallback('intuneRoleDefinition'))->toBeFalse()
        ->and($registry->usesFallback('deviceCompliancePolicy'))->toBeFalse();
});

it('falls back for unknown policy types', function (): void {
    $fallback = new FallbackSnapshotTypeRenderer;
    $registry = new SnapshotTypeRendererRegistry(
        renderers: [
            new IntuneRoleDefinitionSnapshotTypeRenderer,
        ],
        fallbackRenderer: $fallback,
    );

    expect($registry->rendererFor('mysteryPolicyType'))->toBe($fallback)
        ->and($registry->usesFallback('mysteryPolicyType'))->toBeTrue();
});
