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

package com.azure.resourcemanager.purview.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.purview.fluent.models.AccountProperties;
import com.azure.resourcemanager.purview.models.AccountUpdateParameters;
import com.azure.resourcemanager.purview.models.CloudConnectors;
import com.azure.resourcemanager.purview.models.Identity;
import com.azure.resourcemanager.purview.models.PublicNetworkAccess;
import com.azure.resourcemanager.purview.models.Type;
import com.azure.resourcemanager.purview.models.UserAssignedIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AccountUpdateParametersTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AccountUpdateParameters model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"principalId\":\"ddglm\",\"tenantId\":\"hjq\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"e\":{\"clientId\":\"cxmqciwqvhkhix\",\"principalId\":\"gdtopbobjogh\"},\"gvdfgiotkftutq\":{\"clientId\":\"a\",\"principalId\":\"uhrzayvvt\"},\"hzrvqd\":{\"clientId\":\"ngxlefgugnxkrxdq\",\"principalId\":\"dt\"},\"fbowskanyk\":{\"clientId\":\"bhj\",\"principalId\":\"igeho\"}}},\"properties\":{\"cloudConnectors\":{\"awsExternalId\":\"u\"},\"createdAt\":\"2021-06-25T19:06:32Z\",\"createdBy\":\"qyw\",\"createdByObjectId\":\"drvyn\",\"endpoints\":{\"catalog\":\"pphrcgynco\",\"guardian\":\"ecfvmm\",\"scan\":\"ofsx\"},\"friendlyName\":\"evgbmqjq\",\"managedResourceGroupName\":\"c\",\"managedResources\":{\"eventHubNamespace\":\"ivkwlzuvccfwnfnb\",\"resourceGroup\":\"fionl\",\"storageAccount\":\"x\"},\"privateEndpointConnections\":[{\"id\":\"tzxdpnqbqqwx\",\"name\":\"jfeallnwsub\",\"type\":\"snjampmng\"}],\"provisioningState\":\"Moving\",\"publicNetworkAccess\":\"Disabled\"},\"tags\":{\"cbonqvpk\":\"wooc\",\"f\":\"lrxnjeaseiphe\",\"dlwtgrhpdj\":\"okeyyienj\"}}")
                .toObject(AccountUpdateParameters.class);
        Assertions.assertEquals(Type.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("c", model.properties().managedResourceGroupName());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.properties().publicNetworkAccess());
        Assertions.assertEquals("wooc", model.tags().get("cbonqvpk"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AccountUpdateParameters model =
            new AccountUpdateParameters()
                .withIdentity(
                    new Identity()
                        .withType(Type.USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "e",
                                new UserAssignedIdentity(),
                                "gvdfgiotkftutq",
                                new UserAssignedIdentity(),
                                "hzrvqd",
                                new UserAssignedIdentity(),
                                "fbowskanyk",
                                new UserAssignedIdentity())))
                .withProperties(
                    new AccountProperties()
                        .withCloudConnectors(new CloudConnectors())
                        .withManagedResourceGroupName("c")
                        .withPublicNetworkAccess(PublicNetworkAccess.DISABLED))
                .withTags(mapOf("cbonqvpk", "wooc", "f", "lrxnjeaseiphe", "dlwtgrhpdj", "okeyyienj"));
        model = BinaryData.fromObject(model).toObject(AccountUpdateParameters.class);
        Assertions.assertEquals(Type.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("c", model.properties().managedResourceGroupName());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.properties().publicNetworkAccess());
        Assertions.assertEquals("wooc", model.tags().get("cbonqvpk"));
    }

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