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

package com.azure.resourcemanager.deviceupdate.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.deviceupdate.models.AccountUpdate;
import com.azure.resourcemanager.deviceupdate.models.ManagedServiceIdentity;
import com.azure.resourcemanager.deviceupdate.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.deviceupdate.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 AccountUpdateTests {
    @Test
    public void testDeserialize() {
        AccountUpdate model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{\"gnarxzxtheo\":{},\"ivyevcciqihnhun\":{},\"jzrnf\":{},\"gispemvtzfkufubl\":{}}},\"location\":\"fxqeof\",\"tags\":{\"msmjqulngsntn\":\"qjhqjbas\"}}")
                .toObject(AccountUpdate.class);
        Assertions.assertEquals("qjhqjbas", model.tags().get("msmjqulngsntn"));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals("fxqeof", model.location());
    }

    @Test
    public void testSerialize() {
        AccountUpdate model =
            new AccountUpdate()
                .withTags(mapOf("msmjqulngsntn", "qjhqjbas"))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.NONE)
                        .withUserAssignedIdentities(
                            mapOf(
                                "gnarxzxtheo",
                                new UserAssignedIdentity(),
                                "ivyevcciqihnhun",
                                new UserAssignedIdentity(),
                                "jzrnf",
                                new UserAssignedIdentity(),
                                "gispemvtzfkufubl",
                                new UserAssignedIdentity())))
                .withLocation("fxqeof");
        model = BinaryData.fromObject(model).toObject(AccountUpdate.class);
        Assertions.assertEquals("qjhqjbas", model.tags().get("msmjqulngsntn"));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals("fxqeof", model.location());
    }

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