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

package com.azure.resourcemanager.kusto.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.kusto.fluent.models.ClusterInner;
import com.azure.resourcemanager.kusto.models.AzureSku;
import com.azure.resourcemanager.kusto.models.AzureSkuName;
import com.azure.resourcemanager.kusto.models.AzureSkuTier;
import com.azure.resourcemanager.kusto.models.ClusterListResult;
import com.azure.resourcemanager.kusto.models.ClusterNetworkAccessFlag;
import com.azure.resourcemanager.kusto.models.EngineType;
import com.azure.resourcemanager.kusto.models.Identity;
import com.azure.resourcemanager.kusto.models.IdentityType;
import com.azure.resourcemanager.kusto.models.PublicIpType;
import com.azure.resourcemanager.kusto.models.PublicNetworkAccess;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ClusterListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ClusterListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"sku\":{\"name\":\"Standard_E16a_v4\",\"capacity\":1569477308,\"tier\":\"Basic\"},\"zones\":[\"ybcibvyvdcsit\",\"nnaamdectehfiqsc\"],\"identity\":{\"principalId\":\"pvhez\",\"tenantId\":\"gqhcjrefovg\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"state\":\"Creating\",\"provisioningState\":\"Moving\",\"uri\":\"xyqj\",\"dataIngestionUri\":\"cattpngjcrcczsq\",\"stateReason\":\"hvmdajvnysounq\",\"trustedExternalTenants\":[],\"enableDiskEncryption\":true,\"enableStreamingIngest\":true,\"enablePurge\":false,\"enableDoubleEncryption\":false,\"publicNetworkAccess\":\"Enabled\",\"allowedIpRangeList\":[],\"engineType\":\"V3\",\"acceptedAudiences\":[],\"enableAutoStop\":true,\"restrictOutboundNetworkAccess\":\"Enabled\",\"allowedFqdnList\":[],\"publicIPType\":\"IPv4\",\"virtualClusterGraduationProperties\":\"kthfui\",\"privateEndpointConnections\":[]},\"etag\":\"dsfcpkvxodpuoz\",\"location\":\"yzydagfuaxbezyi\",\"tags\":{\"dxwzywqsmbsurexi\":\"ktwh\",\"yocf\":\"o\",\"uxh\":\"fksymddystki\"},\"id\":\"yudxorrqnbp\",\"name\":\"czvyifq\",\"type\":\"vkd\"},{\"sku\":{\"name\":\"Standard_E4a_v4\",\"capacity\":711383541,\"tier\":\"Basic\"},\"zones\":[\"vdfwatkpn\",\"ulexxbczwtr\",\"wiqzbqjvsovmyo\",\"acspkwl\"],\"identity\":{\"principalId\":\"obpxjmflbvvn\",\"tenantId\":\"rkcciwwzjuqk\",\"type\":\"None\",\"userAssignedIdentities\":{}},\"properties\":{\"state\":\"Starting\",\"provisioningState\":\"Succeeded\",\"uri\":\"ofoskghs\",\"dataIngestionUri\":\"uimjmvx\",\"stateReason\":\"duugidyjr\",\"trustedExternalTenants\":[],\"enableDiskEncryption\":false,\"enableStreamingIngest\":true,\"enablePurge\":true,\"enableDoubleEncryption\":false,\"publicNetworkAccess\":\"Disabled\",\"allowedIpRangeList\":[],\"engineType\":\"V3\",\"acceptedAudiences\":[],\"enableAutoStop\":true,\"restrictOutboundNetworkAccess\":\"Enabled\",\"allowedFqdnList\":[],\"publicIPType\":\"DualStack\",\"virtualClusterGraduationProperties\":\"eggzfb\",\"privateEndpointConnections\":[]},\"etag\":\"mvfaxkffeiith\",\"location\":\"vmezy\",\"tags\":{\"grxwbu\":\"xmzsbbzogg\",\"dptkoenkouk\":\"vjxxjnsp\",\"pocipazyxoegu\":\"vudwtiukbldng\",\"npiucgygevqznty\":\"g\"},\"id\":\"mrbpizcdrqj\",\"name\":\"dpydn\",\"type\":\"yhxdeoejzicwi\"}]}")
                .toObject(ClusterListResult.class);
        Assertions.assertEquals("yzydagfuaxbezyi", model.value().get(0).location());
        Assertions.assertEquals("ktwh", model.value().get(0).tags().get("dxwzywqsmbsurexi"));
        Assertions.assertEquals(AzureSkuName.STANDARD_E16A_V4, model.value().get(0).sku().name());
        Assertions.assertEquals(1569477308, model.value().get(0).sku().capacity());
        Assertions.assertEquals(AzureSkuTier.BASIC, model.value().get(0).sku().tier());
        Assertions.assertEquals("ybcibvyvdcsit", model.value().get(0).zones().get(0));
        Assertions.assertEquals(IdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals(true, model.value().get(0).enableDiskEncryption());
        Assertions.assertEquals(true, model.value().get(0).enableStreamingIngest());
        Assertions.assertEquals(false, model.value().get(0).enablePurge());
        Assertions.assertEquals(false, model.value().get(0).enableDoubleEncryption());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(EngineType.V3, model.value().get(0).engineType());
        Assertions.assertEquals(true, model.value().get(0).enableAutoStop());
        Assertions.assertEquals(ClusterNetworkAccessFlag.ENABLED, model.value().get(0).restrictOutboundNetworkAccess());
        Assertions.assertEquals(PublicIpType.IPV4, model.value().get(0).publicIpType());
        Assertions.assertEquals("kthfui", model.value().get(0).virtualClusterGraduationProperties());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ClusterListResult model =
            new ClusterListResult()
                .withValue(
                    Arrays
                        .asList(
                            new ClusterInner()
                                .withLocation("yzydagfuaxbezyi")
                                .withTags(mapOf("dxwzywqsmbsurexi", "ktwh", "yocf", "o", "uxh", "fksymddystki"))
                                .withSku(
                                    new AzureSku()
                                        .withName(AzureSkuName.STANDARD_E16A_V4)
                                        .withCapacity(1569477308)
                                        .withTier(AzureSkuTier.BASIC))
                                .withZones(Arrays.asList("ybcibvyvdcsit", "nnaamdectehfiqsc"))
                                .withIdentity(
                                    new Identity()
                                        .withType(IdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withTrustedExternalTenants(Arrays.asList())
                                .withEnableDiskEncryption(true)
                                .withEnableStreamingIngest(true)
                                .withEnablePurge(false)
                                .withEnableDoubleEncryption(false)
                                .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                                .withAllowedIpRangeList(Arrays.asList())
                                .withEngineType(EngineType.V3)
                                .withAcceptedAudiences(Arrays.asList())
                                .withEnableAutoStop(true)
                                .withRestrictOutboundNetworkAccess(ClusterNetworkAccessFlag.ENABLED)
                                .withAllowedFqdnList(Arrays.asList())
                                .withPublicIpType(PublicIpType.IPV4)
                                .withVirtualClusterGraduationProperties("kthfui"),
                            new ClusterInner()
                                .withLocation("vmezy")
                                .withTags(
                                    mapOf(
                                        "grxwbu",
                                        "xmzsbbzogg",
                                        "dptkoenkouk",
                                        "vjxxjnsp",
                                        "pocipazyxoegu",
                                        "vudwtiukbldng",
                                        "npiucgygevqznty",
                                        "g"))
                                .withSku(
                                    new AzureSku()
                                        .withName(AzureSkuName.STANDARD_E4A_V4)
                                        .withCapacity(711383541)
                                        .withTier(AzureSkuTier.BASIC))
                                .withZones(Arrays.asList("vdfwatkpn", "ulexxbczwtr", "wiqzbqjvsovmyo", "acspkwl"))
                                .withIdentity(
                                    new Identity().withType(IdentityType.NONE).withUserAssignedIdentities(mapOf()))
                                .withTrustedExternalTenants(Arrays.asList())
                                .withEnableDiskEncryption(false)
                                .withEnableStreamingIngest(true)
                                .withEnablePurge(true)
                                .withEnableDoubleEncryption(false)
                                .withPublicNetworkAccess(PublicNetworkAccess.DISABLED)
                                .withAllowedIpRangeList(Arrays.asList())
                                .withEngineType(EngineType.V3)
                                .withAcceptedAudiences(Arrays.asList())
                                .withEnableAutoStop(true)
                                .withRestrictOutboundNetworkAccess(ClusterNetworkAccessFlag.ENABLED)
                                .withAllowedFqdnList(Arrays.asList())
                                .withPublicIpType(PublicIpType.DUAL_STACK)
                                .withVirtualClusterGraduationProperties("eggzfb")));
        model = BinaryData.fromObject(model).toObject(ClusterListResult.class);
        Assertions.assertEquals("yzydagfuaxbezyi", model.value().get(0).location());
        Assertions.assertEquals("ktwh", model.value().get(0).tags().get("dxwzywqsmbsurexi"));
        Assertions.assertEquals(AzureSkuName.STANDARD_E16A_V4, model.value().get(0).sku().name());
        Assertions.assertEquals(1569477308, model.value().get(0).sku().capacity());
        Assertions.assertEquals(AzureSkuTier.BASIC, model.value().get(0).sku().tier());
        Assertions.assertEquals("ybcibvyvdcsit", model.value().get(0).zones().get(0));
        Assertions.assertEquals(IdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals(true, model.value().get(0).enableDiskEncryption());
        Assertions.assertEquals(true, model.value().get(0).enableStreamingIngest());
        Assertions.assertEquals(false, model.value().get(0).enablePurge());
        Assertions.assertEquals(false, model.value().get(0).enableDoubleEncryption());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(EngineType.V3, model.value().get(0).engineType());
        Assertions.assertEquals(true, model.value().get(0).enableAutoStop());
        Assertions.assertEquals(ClusterNetworkAccessFlag.ENABLED, model.value().get(0).restrictOutboundNetworkAccess());
        Assertions.assertEquals(PublicIpType.IPV4, model.value().get(0).publicIpType());
        Assertions.assertEquals("kthfui", model.value().get(0).virtualClusterGraduationProperties());
    }

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