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

package com.azure.resourcemanager.hdinsight.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.hdinsight.models.ClusterIdentity;
import com.azure.resourcemanager.hdinsight.models.ResourceIdentityType;
import com.azure.resourcemanager.hdinsight.models.UserAssignedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class ClusterIdentityTests {
    @Test
    public void testDeserialize() {
        ClusterIdentity model =
            BinaryData
                .fromString(
                    "{\"principalId\":\"u\",\"tenantId\":\"a\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"tthzrvqd\":{\"principalId\":\"vvtpgvdfgio\",\"clientId\":\"ftutqxlngxlefgu\",\"tenantId\":\"xkrxdqmi\"},\"nyktzlcuiy\":{\"principalId\":\"bhj\",\"clientId\":\"igeho\",\"tenantId\":\"bowsk\"},\"ocpecfvmmco\":{\"principalId\":\"qyw\",\"clientId\":\"drvyn\",\"tenantId\":\"gpphrcgyn\"}}}")
                .toObject(ClusterIdentity.class);
        Assertions.assertEquals(ResourceIdentityType.USER_ASSIGNED, model.type());
        Assertions.assertEquals("xkrxdqmi", model.userAssignedIdentities().get("tthzrvqd").tenantId());
    }

    @Test
    public void testSerialize() {
        ClusterIdentity model =
            new ClusterIdentity()
                .withType(ResourceIdentityType.USER_ASSIGNED)
                .withUserAssignedIdentities(
                    mapOf(
                        "tthzrvqd",
                        new UserAssignedIdentity().withTenantId("xkrxdqmi"),
                        "nyktzlcuiy",
                        new UserAssignedIdentity().withTenantId("bowsk"),
                        "ocpecfvmmco",
                        new UserAssignedIdentity().withTenantId("gpphrcgyn")));
        model = BinaryData.fromObject(model).toObject(ClusterIdentity.class);
        Assertions.assertEquals(ResourceIdentityType.USER_ASSIGNED, model.type());
        Assertions.assertEquals("xkrxdqmi", model.userAssignedIdentities().get("tthzrvqd").tenantId());
    }

    @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;
    }
}
