<?php

use App\Services\Intune\DeviceConfigurationPolicyNormalizer;

it('builds a configuration block for device configuration policies', function () {
    $normalizer = app(DeviceConfigurationPolicyNormalizer::class);

    $snapshot = [
        '@odata.type' => '#microsoft.graph.windows10CustomConfiguration',
        'displayName' => 'Device Config Policy',
        'description' => 'Test policy',
        'omaSettings' => [
            [
                'displayName' => 'Setting A',
                'omaUri' => './Vendor/MSFT/SettingA',
                'value' => 'Enabled',
            ],
        ],
        'customSetting' => 'Custom value',
        'nestedSetting' => ['value' => 'Nested'],
    ];

    $normalized = $normalizer->normalize($snapshot, 'deviceConfiguration', 'windows');
    $settings = collect($normalized['settings']);

    $omaBlock = $settings->firstWhere('title', 'OMA-URI settings');
    expect($omaBlock)->not->toBeNull();

    $configurationBlock = $settings->firstWhere('title', 'Configuration');
    expect($configurationBlock)->not->toBeNull();

    $labels = collect($configurationBlock['entries'])->pluck('key')->all();
    expect($labels)->toContain('Custom Setting', 'Nested Setting');
    expect($labels)->not->toContain('Display Name');

    expect($settings->pluck('title')->all())->not->toContain('General');
});
