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

package com.azure.resourcemanager.netapp.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.netapp.models.ManagedServiceIdentity;
import com.azure.resourcemanager.netapp.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.netapp.models.UserAssignedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ManagedServiceIdentityTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ManagedServiceIdentity model =
            BinaryData
                .fromString(
                    "{\"principalId\":\"b08e5065-c2d7-4c58-96f9-5287dc9ea765\",\"tenantId\":\"20af4492-d6c4-4406-afd3-7371b6caa8eb\",\"type\":\"None\",\"userAssignedIdentities\":{\"jfeallnwsub\":{\"principalId\":\"df6efb0e-0d53-47c7-9200-e52ecda72f1e\",\"clientId\":\"eb37883f-1094-4bdc-814a-af9d3fc93e04\"},\"jampmngnzscxaqw\":{\"principalId\":\"2730aa5b-9a50-4480-a8c8-9e61859de826\",\"clientId\":\"07aada81-b718-46a3-8975-ef02d6b68da5\"},\"hcbonqvpkvlr\":{\"principalId\":\"b15cab05-1bc0-49af-8bcf-e6cc585702c3\",\"clientId\":\"fbf982d5-e2f3-446b-8b46-3e9f66888c40\"},\"ea\":{\"principalId\":\"6f84b040-5de6-4797-ad21-1f16f4ac11fb\",\"clientId\":\"8f6139d5-6ecd-4ad6-aa8c-a6baf394265f\"}}}")
                .toObject(ManagedServiceIdentity.class);
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ManagedServiceIdentity model =
            new ManagedServiceIdentity()
                .withType(ManagedServiceIdentityType.NONE)
                .withUserAssignedIdentities(
                    mapOf(
                        "jfeallnwsub",
                        new UserAssignedIdentity(),
                        "jampmngnzscxaqw",
                        new UserAssignedIdentity(),
                        "hcbonqvpkvlr",
                        new UserAssignedIdentity(),
                        "ea",
                        new UserAssignedIdentity()));
        model = BinaryData.fromObject(model).toObject(ManagedServiceIdentity.class);
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, 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;
    }
}
