<?php

declare(strict_types=1);

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

it('renders structured compliance details when metadata is available', function (): void {
    $renderer = new DeviceComplianceSnapshotTypeRenderer;

    $item = new BaselineSnapshotItem([
        'policy_type' => 'deviceCompliancePolicy',
        'subject_key' => 'bitlocker require',
        'subject_external_id' => hash('sha256', 'deviceCompliancePolicy|bitlocker require'),
        'meta_jsonb' => [
            'display_name' => 'Bitlocker Require',
            'platform' => 'windows',
            'odata_type' => '#microsoft.graph.windows10CompliancePolicy',
            'assignment_target_count' => 3,
            'evidence' => [
                'fidelity' => 'meta',
                'source' => 'inventory',
                'observed_at' => '2026-03-09T12:00:00+00:00',
            ],
        ],
    ]);

    $rendered = $renderer->render($item)->toArray();
    $attributes = collect($rendered['structuredAttributes'])->keyBy('label');

    expect($rendered['label'])->toBe('Bitlocker Require')
        ->and($rendered['fidelity'])->toBe('reference_only')
        ->and($attributes['Platform']['value'])->toBe('Windows')
        ->and($attributes['Assignment targets']['value'])->toBe('3')
        ->and($attributes['OData type']['value'])->toBe('#microsoft.graph.windows10CompliancePolicy');
});
