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

package com.azure.resourcemanager.machinelearning.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.machinelearning.models.ManagedServiceIdentity;
import com.azure.resourcemanager.machinelearning.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.machinelearning.models.PublicNetworkAccess;
import com.azure.resourcemanager.machinelearning.models.ServiceManagedResourcesSettings;
import com.azure.resourcemanager.machinelearning.models.Sku;
import com.azure.resourcemanager.machinelearning.models.SkuTier;
import com.azure.resourcemanager.machinelearning.models.UserAssignedIdentity;
import com.azure.resourcemanager.machinelearning.models.WorkspaceUpdateParameters;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class WorkspaceUpdateParametersTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WorkspaceUpdateParameters model =
            BinaryData
                .fromString(
                    "{\"tags\":{\"yqduujit\":\"mgxsab\",\"rwpdappdsbdkvwrw\":\"jczdzevndh\"},\"sku\":{\"name\":\"eusnhutj\",\"tier\":\"Premium\",\"size\":\"rl\",\"family\":\"ugjzzdatqxhocdge\",\"capacity\":1293628182},\"identity\":{\"principalId\":\"1766dab0-b6cc-422f-8a7a-5b439fec6fab\",\"tenantId\":\"31064613-1bc8-43cc-a67e-db3b41e6f75c\",\"type\":\"SystemAssigned,UserAssigned\",\"userAssignedIdentities\":{\"dvkaozw\":{\"principalId\":\"47285ad5-2fb1-4802-9800-ef15b64c9005\",\"clientId\":\"3461706a-d43b-4f70-a1e5-f37623e988fb\"},\"tyhxhurokft\":{\"principalId\":\"141163eb-a84e-4057-876d-ef2ca332a35a\",\"clientId\":\"61aace7e-3ef4-41e3-a5f3-cb34b3814d76\"},\"lniwpwcukjfkgiaw\":{\"principalId\":\"d961710b-4bea-4db4-ae21-054935aa3b87\",\"clientId\":\"52a95018-46dd-4fa9-860b-f8dafc12a373\"},\"ryplwckbasyypn\":{\"principalId\":\"14d938eb-6659-4bd4-b080-10c086f54a8e\",\"clientId\":\"a92d70a9-dbe7-4b71-a2b5-0096f3797152\"}}},\"properties\":{\"description\":\"sgcbac\",\"friendlyName\":\"ejk\",\"imageBuildCompute\":\"ynqgoulzndlikwyq\",\"serviceManagedResourcesSettings\":{},\"primaryUserAssignedIdentity\":\"ibmadgakeqsrxy\",\"publicNetworkAccess\":\"Disabled\",\"applicationInsights\":\"e\",\"containerRegistry\":\"ytb\"}}")
                .toObject(WorkspaceUpdateParameters.class);
        Assertions.assertEquals("mgxsab", model.tags().get("yqduujit"));
        Assertions.assertEquals("eusnhutj", model.sku().name());
        Assertions.assertEquals(SkuTier.PREMIUM, model.sku().tier());
        Assertions.assertEquals("rl", model.sku().size());
        Assertions.assertEquals("ugjzzdatqxhocdge", model.sku().family());
        Assertions.assertEquals(1293628182, model.sku().capacity());
        Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("sgcbac", model.description());
        Assertions.assertEquals("ejk", model.friendlyName());
        Assertions.assertEquals("ynqgoulzndlikwyq", model.imageBuildCompute());
        Assertions.assertEquals("ibmadgakeqsrxy", model.primaryUserAssignedIdentity());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.publicNetworkAccess());
        Assertions.assertEquals("e", model.applicationInsights());
        Assertions.assertEquals("ytb", model.containerRegistry());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WorkspaceUpdateParameters model =
            new WorkspaceUpdateParameters()
                .withTags(mapOf("yqduujit", "mgxsab", "rwpdappdsbdkvwrw", "jczdzevndh"))
                .withSku(
                    new Sku()
                        .withName("eusnhutj")
                        .withTier(SkuTier.PREMIUM)
                        .withSize("rl")
                        .withFamily("ugjzzdatqxhocdge")
                        .withCapacity(1293628182))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "dvkaozw",
                                new UserAssignedIdentity(),
                                "tyhxhurokft",
                                new UserAssignedIdentity(),
                                "lniwpwcukjfkgiaw",
                                new UserAssignedIdentity(),
                                "ryplwckbasyypn",
                                new UserAssignedIdentity())))
                .withDescription("sgcbac")
                .withFriendlyName("ejk")
                .withImageBuildCompute("ynqgoulzndlikwyq")
                .withServiceManagedResourcesSettings(new ServiceManagedResourcesSettings())
                .withPrimaryUserAssignedIdentity("ibmadgakeqsrxy")
                .withPublicNetworkAccess(PublicNetworkAccess.DISABLED)
                .withApplicationInsights("e")
                .withContainerRegistry("ytb");
        model = BinaryData.fromObject(model).toObject(WorkspaceUpdateParameters.class);
        Assertions.assertEquals("mgxsab", model.tags().get("yqduujit"));
        Assertions.assertEquals("eusnhutj", model.sku().name());
        Assertions.assertEquals(SkuTier.PREMIUM, model.sku().tier());
        Assertions.assertEquals("rl", model.sku().size());
        Assertions.assertEquals("ugjzzdatqxhocdge", model.sku().family());
        Assertions.assertEquals(1293628182, model.sku().capacity());
        Assertions.assertEquals(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("sgcbac", model.description());
        Assertions.assertEquals("ejk", model.friendlyName());
        Assertions.assertEquals("ynqgoulzndlikwyq", model.imageBuildCompute());
        Assertions.assertEquals("ibmadgakeqsrxy", model.primaryUserAssignedIdentity());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.publicNetworkAccess());
        Assertions.assertEquals("e", model.applicationInsights());
        Assertions.assertEquals("ytb", model.containerRegistry());
    }

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