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

package com.azure.resourcemanager.databricks.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.databricks.fluent.models.WorkspaceInner;
import com.azure.resourcemanager.databricks.models.PublicNetworkAccess;
import com.azure.resourcemanager.databricks.models.RequiredNsgRules;
import com.azure.resourcemanager.databricks.models.Sku;
import com.azure.resourcemanager.databricks.models.WorkspaceListResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class WorkspaceListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WorkspaceListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"managedResourceGroupId\":\"wzwbnguitn\",\"provisioningState\":\"Created\",\"uiDefinitionUri\":\"a\",\"authorizations\":[],\"createdDateTime\":\"2020-12-27T04:43:40Z\",\"workspaceId\":\"ckyfih\",\"workspaceUrl\":\"idf\",\"diskEncryptionSetId\":\"zuhtymwisdkfthwx\",\"privateEndpointConnections\":[],\"publicNetworkAccess\":\"Enabled\",\"requiredNsgRules\":\"NoAzureServiceRules\"},\"sku\":{\"name\":\"pvkmijcmmxdcuf\",\"tier\":\"srp\"},\"location\":\"zidnsezcxtbzsgfy\",\"tags\":{\"sflnrosfqp\":\"newmdwzjeiachbo\"},\"id\":\"eeh\",\"name\":\"zvypyqrimzinp\",\"type\":\"swjdkirso\"},{\"properties\":{\"managedResourceGroupId\":\"dqxhcrmnohjtckwh\",\"provisioningState\":\"Canceled\",\"uiDefinitionUri\":\"iy\",\"authorizations\":[],\"createdDateTime\":\"2021-02-24T22:15:36Z\",\"workspaceId\":\"pgrjbz\",\"workspaceUrl\":\"rcjxvsnbyxqabn\",\"diskEncryptionSetId\":\"cyshurzafbljjgp\",\"privateEndpointConnections\":[],\"publicNetworkAccess\":\"Enabled\",\"requiredNsgRules\":\"NoAzureDatabricksRules\"},\"sku\":{\"name\":\"ljavbqid\",\"tier\":\"ajzyul\"},\"location\":\"u\",\"tags\":{\"xzlocxscp\":\"rlkhbzhfepgzgq\",\"j\":\"ierhhbcsglummaj\",\"jionpimexgstxgc\":\"odxobnbdxkqpxok\"},\"id\":\"odgmaajrmvdjwz\",\"name\":\"lovmclwhijcoe\",\"type\":\"ctbzaq\"}],\"nextLink\":\"sycbkbfk\"}")
                .toObject(WorkspaceListResult.class);
        Assertions.assertEquals("zidnsezcxtbzsgfy", model.value().get(0).location());
        Assertions.assertEquals("newmdwzjeiachbo", model.value().get(0).tags().get("sflnrosfqp"));
        Assertions.assertEquals("pvkmijcmmxdcuf", model.value().get(0).sku().name());
        Assertions.assertEquals("srp", model.value().get(0).sku().tier());
        Assertions.assertEquals("wzwbnguitn", model.value().get(0).managedResourceGroupId());
        Assertions.assertEquals("a", model.value().get(0).uiDefinitionUri());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(RequiredNsgRules.NO_AZURE_SERVICE_RULES, model.value().get(0).requiredNsgRules());
        Assertions.assertEquals("sycbkbfk", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WorkspaceListResult model =
            new WorkspaceListResult()
                .withValue(
                    Arrays
                        .asList(
                            new WorkspaceInner()
                                .withLocation("zidnsezcxtbzsgfy")
                                .withTags(mapOf("sflnrosfqp", "newmdwzjeiachbo"))
                                .withSku(new Sku().withName("pvkmijcmmxdcuf").withTier("srp"))
                                .withManagedResourceGroupId("wzwbnguitn")
                                .withUiDefinitionUri("a")
                                .withAuthorizations(Arrays.asList())
                                .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                                .withRequiredNsgRules(RequiredNsgRules.NO_AZURE_SERVICE_RULES),
                            new WorkspaceInner()
                                .withLocation("u")
                                .withTags(
                                    mapOf(
                                        "xzlocxscp",
                                        "rlkhbzhfepgzgq",
                                        "j",
                                        "ierhhbcsglummaj",
                                        "jionpimexgstxgc",
                                        "odxobnbdxkqpxok"))
                                .withSku(new Sku().withName("ljavbqid").withTier("ajzyul"))
                                .withManagedResourceGroupId("dqxhcrmnohjtckwh")
                                .withUiDefinitionUri("iy")
                                .withAuthorizations(Arrays.asList())
                                .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                                .withRequiredNsgRules(RequiredNsgRules.NO_AZURE_DATABRICKS_RULES)))
                .withNextLink("sycbkbfk");
        model = BinaryData.fromObject(model).toObject(WorkspaceListResult.class);
        Assertions.assertEquals("zidnsezcxtbzsgfy", model.value().get(0).location());
        Assertions.assertEquals("newmdwzjeiachbo", model.value().get(0).tags().get("sflnrosfqp"));
        Assertions.assertEquals("pvkmijcmmxdcuf", model.value().get(0).sku().name());
        Assertions.assertEquals("srp", model.value().get(0).sku().tier());
        Assertions.assertEquals("wzwbnguitn", model.value().get(0).managedResourceGroupId());
        Assertions.assertEquals("a", model.value().get(0).uiDefinitionUri());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(RequiredNsgRules.NO_AZURE_SERVICE_RULES, model.value().get(0).requiredNsgRules());
        Assertions.assertEquals("sycbkbfk", model.nextLink());
    }

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