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

package com.azure.resourcemanager.appcontainers.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.appcontainers.models.ManagedServiceIdentity;
import com.azure.resourcemanager.appcontainers.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.appcontainers.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\":\"24eebd10-bf80-4224-a885-dc9084199200\",\"tenantId\":\"3c475488-292b-422c-81d4-240c0898d233\",\"type\":\"SystemAssigned,UserAssigned\",\"userAssignedIdentities\":{\"cjhwq\":{\"principalId\":\"fcd4ddb6-77d0-4861-9a96-0c321ff8271d\",\"clientId\":\"43c0c199-a1e9-4807-84d3-a12f37c5fbfe\"},\"r\":{\"principalId\":\"d8346bc1-ffe5-4f69-b84d-b7ac8ad8a9c5\",\"clientId\":\"667b8c4d-698b-4d40-b6bc-9beef6128b9c\"},\"wj\":{\"principalId\":\"9602c6fb-0ebf-4759-9052-e11914dd8bd4\",\"clientId\":\"79d13a9b-ad01-41f8-993a-83d259b301d4\"}}}")
                .toObject(ManagedServiceIdentity.class);
        Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED, model.type());
    }

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