// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.paloaltonetworks.ngfw.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.AzureResourceManagerManagedIdentityProperties;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.AzureResourceManagerUserAssignedIdentity;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.ManagedIdentityType;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AzureResourceManagerManagedIdentityPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureResourceManagerManagedIdentityProperties model =
            BinaryData
                .fromString(
                    "{\"tenantId\":\"appd\",\"principalId\":\"dkvwrwjfe\",\"type\":\"None\",\"userAssignedIdentities\":{\"cdgea\":{\"clientId\":\"tjelt\",\"principalId\":\"ldhugjzzdatqxh\"},\"k\":{\"clientId\":\"gphuticndvka\",\"principalId\":\"wyiftyhxhur\"}}}")
                .toObject(AzureResourceManagerManagedIdentityProperties.class);
        Assertions.assertEquals(ManagedIdentityType.NONE, model.type());
        Assertions.assertEquals("tjelt", model.userAssignedIdentities().get("cdgea").clientId());
        Assertions.assertEquals("ldhugjzzdatqxh", model.userAssignedIdentities().get("cdgea").principalId());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureResourceManagerManagedIdentityProperties model =
            new AzureResourceManagerManagedIdentityProperties()
                .withType(ManagedIdentityType.NONE)
                .withUserAssignedIdentities(
                    mapOf(
                        "cdgea",
                        new AzureResourceManagerUserAssignedIdentity()
                            .withClientId("tjelt")
                            .withPrincipalId("ldhugjzzdatqxh"),
                        "k",
                        new AzureResourceManagerUserAssignedIdentity()
                            .withClientId("gphuticndvka")
                            .withPrincipalId("wyiftyhxhur")));
        model = BinaryData.fromObject(model).toObject(AzureResourceManagerManagedIdentityProperties.class);
        Assertions.assertEquals(ManagedIdentityType.NONE, model.type());
        Assertions.assertEquals("tjelt", model.userAssignedIdentities().get("cdgea").clientId());
        Assertions.assertEquals("ldhugjzzdatqxh", model.userAssignedIdentities().get("cdgea").principalId());
    }

    @SuppressWarnings("unchecked")
    private static <T> Map<String, T> mapOf(Object... inputs) {
        Map<String, T> map = new HashMap<>();
        for (int i = 0; i < inputs.length; i += 2) {
            String key = (String) inputs[i];
            T value = (T) inputs[i + 1];
            map.put(key, value);
        }
        return map;
    }
}
