<?php

declare(strict_types=1);

use App\Models\BaselineSnapshotItem;
use App\Services\Baselines\SnapshotRendering\Renderers\FallbackSnapshotTypeRenderer;

it('renders a minimum contract for unsupported snapshot types', function (): void {
    $renderer = new FallbackSnapshotTypeRenderer;

    $item = new BaselineSnapshotItem([
        'policy_type' => 'mysteryPolicyType',
        'subject_key' => 'mystery policy',
        'subject_external_id' => hash('sha256', 'mysteryPolicyType|mystery policy'),
        'meta_jsonb' => [
            'display_name' => 'Mystery Policy',
            'category' => 'Other',
            'platform' => 'windows',
            'evidence' => [
                'fidelity' => 'content',
                'source' => 'policy_version',
                'observed_at' => '2026-03-09T12:00:00+00:00',
            ],
        ],
    ]);

    $rendered = $renderer->render($item)->toArray();

    expect($rendered['label'])->toBe('Mystery Policy')
        ->and($rendered['typeLabel'])->toBe('Mystery Policy Type')
        ->and($rendered['referenceStatus'])->toBe('Policy version')
        ->and($rendered['fidelity'])->toBe('unsupported')
        ->and(data_get($rendered, 'gapSummary.has_gaps'))->toBeFalse()
        ->and(data_get($rendered, 'gapSummary.messages.0'))->toBe('A fallback renderer is being used for this item.')
        ->and(collect($rendered['structuredAttributes'])->pluck('label')->all())
        ->toContain('Category', 'Platform', 'Evidence source');
});
