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

package com.azure.resourcemanager.mediaservices.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.mediaservices.models.MediaServiceIdentity;
import com.azure.resourcemanager.mediaservices.models.UserAssignedManagedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class MediaServiceIdentityTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        MediaServiceIdentity model =
            BinaryData
                .fromString(
                    "{\"type\":\"qjqabcypmivkwl\",\"principalId\":\"a55eb1ba-077c-4c10-bdf5-fee3de755d37\",\"tenantId\":\"c6587608-fedb-4a8a-8730-0fefc209bdb3\",\"userAssignedIdentities\":{\"nfnbacfionlebxe\":{\"clientId\":\"8f741151-f5d3-4373-9827-f9d180571118\",\"principalId\":\"4b30cea5-74e4-41a4-8a09-85cb7083f2b3\"}}}")
                .toObject(MediaServiceIdentity.class);
        Assertions.assertEquals("qjqabcypmivkwl", model.type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        MediaServiceIdentity model =
            new MediaServiceIdentity()
                .withType("qjqabcypmivkwl")
                .withUserAssignedIdentities(mapOf("nfnbacfionlebxe", new UserAssignedManagedIdentity()));
        model = BinaryData.fromObject(model).toObject(MediaServiceIdentity.class);
        Assertions.assertEquals("qjqabcypmivkwl", 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;
    }
}
