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

package com.azure.resourcemanager.synapse.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.synapse.models.ManagedIdentity;
import com.azure.resourcemanager.synapse.models.ResourceIdentityType;
import com.azure.resourcemanager.synapse.models.UserAssignedManagedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ManagedIdentityTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ManagedIdentity model =
            BinaryData
                .fromString(
                    "{\"principalId\":\"ddyvvjskgfmo\",\"tenantId\":\"83f756fc-ba99-4f6f-abf8-45dc84541b54\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{\"tjeaahhvjhh\":{\"clientId\":\"bf52dee7-0664-441f-809b-5e69007ef11b\",\"principalId\":\"3aa66067-17f3-44fb-99cf-205da1c152f2\"},\"zybbj\":{\"clientId\":\"0c631fe0-e671-415f-a9fc-bf6ba14da35e\",\"principalId\":\"70f0a1be-5d32-4ca6-b8d2-df225199043f\"},\"jks\":{\"clientId\":\"4ce29efb-a2e4-48b2-acf0-8bafc2106bb5\",\"principalId\":\"dfb475a2-3c00-4d35-ae90-9cebc91c3124\"},\"yxvxevblbjed\":{\"clientId\":\"0f9fc1fd-de08-45c4-9892-1a46ddd831c0\",\"principalId\":\"e66c4165-b322-403a-89fa-acb8b979cb30\"}}}")
                .toObject(ManagedIdentity.class);
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ManagedIdentity model =
            new ManagedIdentity()
                .withType(ResourceIdentityType.SYSTEM_ASSIGNED)
                .withUserAssignedIdentities(
                    mapOf(
                        "tjeaahhvjhh",
                        new UserAssignedManagedIdentity(),
                        "zybbj",
                        new UserAssignedManagedIdentity(),
                        "jks",
                        new UserAssignedManagedIdentity(),
                        "yxvxevblbjed",
                        new UserAssignedManagedIdentity()));
        model = BinaryData.fromObject(model).toObject(ManagedIdentity.class);
        Assertions.assertEquals(ResourceIdentityType.SYSTEM_ASSIGNED, model.type());
    }

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