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

package com.azure.resourcemanager.redisenterprise.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.redisenterprise.fluent.models.ClusterInner;
import com.azure.resourcemanager.redisenterprise.models.ClusterList;
import com.azure.resourcemanager.redisenterprise.models.ManagedServiceIdentity;
import com.azure.resourcemanager.redisenterprise.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.redisenterprise.models.Sku;
import com.azure.resourcemanager.redisenterprise.models.SkuName;
import com.azure.resourcemanager.redisenterprise.models.TlsVersion;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ClusterListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ClusterList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"sku\":{\"name\":\"Enterprise_E100\",\"capacity\":757698897},\"zones\":[\"l\",\"ndlik\",\"yqkgfg\"],\"identity\":{\"principalId\":\"90eff83e-825f-48f3-965e-3d795be6a629\",\"tenantId\":\"75977f0f-8699-47eb-a4d1-da4ff4ec7b73\",\"type\":\"None\",\"userAssignedIdentities\":{}},\"properties\":{\"minimumTlsVersion\":\"1.1\",\"hostName\":\"rxybz\",\"provisioningState\":\"Canceled\",\"resourceState\":\"Disabled\",\"redisVersion\":\"tbciqfouflmm\",\"privateEndpointConnections\":[]},\"location\":\"smodmgloug\",\"tags\":{\"ta\":\"wtmutduq\",\"whbmd\":\"spwgcuertumkdosv\",\"bhtqqrolfpfpsa\":\"bbjfddgmbmbexp\",\"jgzjaoyfhrtx\":\"gbquxigj\"},\"id\":\"lnerkujysvleju\",\"name\":\"fqawrlyxw\",\"type\":\"kcprbnw\"},{\"sku\":{\"name\":\"EnterpriseFlash_F1500\",\"capacity\":19976049},\"zones\":[\"bvpyss\",\"dnrujqguhmuouqfp\",\"wzwbnguitn\"],\"identity\":{\"principalId\":\"c00a688f-e999-484c-a8a0-66e1185caef2\",\"tenantId\":\"2cbddb9d-555d-4e1d-bad2-29624caf2ff6\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"minimumTlsVersion\":\"1.1\",\"hostName\":\"zuckyfi\",\"provisioningState\":\"Creating\",\"resourceState\":\"EnableFailed\",\"redisVersion\":\"vzwdzuhtymwis\",\"privateEndpointConnections\":[]},\"location\":\"thwxmnteiwaopvkm\",\"tags\":{\"uf\":\"mmxdcu\"},\"id\":\"rpymzidnsez\",\"name\":\"xtbzsgfyccsne\",\"type\":\"mdwzjeiachboo\"},{\"sku\":{\"name\":\"Enterprise_E20\",\"capacity\":219333087},\"zones\":[\"sfqpteehz\",\"vypyqrimzinpv\",\"wjdk\"],\"identity\":{\"principalId\":\"3bd9ea38-b56c-4244-85ed-751adf8ece99\",\"tenantId\":\"e55d238e-b999-422a-bc19-990b3d105f10\",\"type\":\"None\",\"userAssignedIdentities\":{}},\"properties\":{\"minimumTlsVersion\":\"1.0\",\"hostName\":\"mnoh\",\"provisioningState\":\"Failed\",\"resourceState\":\"Running\",\"redisVersion\":\"dsoifiyipj\",\"privateEndpointConnections\":[]},\"location\":\"wpgrjbzno\",\"tags\":{\"nb\":\"xv\",\"rzafbljjgpbtoqcj\":\"xqabnmocpcysh\",\"vbqid\":\"klj\"},\"id\":\"qajzyulpkudjkr\",\"name\":\"khbzhfepgzg\",\"type\":\"e\"},{\"sku\":{\"name\":\"Enterprise_E20\",\"capacity\":1678385538},\"zones\":[\"scpai\",\"rhhbcs\",\"l\"],\"identity\":{\"principalId\":\"7b158bd3-97df-4c2a-ac7e-1b2217741991\",\"tenantId\":\"e484b802-9883-4733-a687-d29514741b98\",\"type\":\"SystemAssigned,"
                        + " UserAssigned\",\"userAssignedIdentities\":{}},\"properties\":{\"minimumTlsVersion\":\"1.2\",\"hostName\":\"obnbdxkqpxokaj\",\"provisioningState\":\"Succeeded\",\"resourceState\":\"Disabling\",\"redisVersion\":\"ex\",\"privateEndpointConnections\":[]},\"location\":\"xgcp\",\"tags\":{\"mcl\":\"maajrmvdjwzrlo\",\"jctbza\":\"hijco\"},\"id\":\"s\",\"name\":\"sycbkbfk\",\"type\":\"ukdkexxppofmxa\"}],\"nextLink\":\"fjpgddtocjjxhvp\"}")
                .toObject(ClusterList.class);
        Assertions.assertEquals("smodmgloug", model.value().get(0).location());
        Assertions.assertEquals("wtmutduq", model.value().get(0).tags().get("ta"));
        Assertions.assertEquals(SkuName.ENTERPRISE_E100, model.value().get(0).sku().name());
        Assertions.assertEquals(757698897, model.value().get(0).sku().capacity());
        Assertions.assertEquals("l", model.value().get(0).zones().get(0));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals(TlsVersion.ONE_ONE, model.value().get(0).minimumTlsVersion());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ClusterList model =
            new ClusterList()
                .withValue(
                    Arrays
                        .asList(
                            new ClusterInner()
                                .withLocation("smodmgloug")
                                .withTags(
                                    mapOf(
                                        "ta",
                                        "wtmutduq",
                                        "whbmd",
                                        "spwgcuertumkdosv",
                                        "bhtqqrolfpfpsa",
                                        "bbjfddgmbmbexp",
                                        "jgzjaoyfhrtx",
                                        "gbquxigj"))
                                .withSku(new Sku().withName(SkuName.ENTERPRISE_E100).withCapacity(757698897))
                                .withZones(Arrays.asList("l", "ndlik", "yqkgfg"))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withMinimumTlsVersion(TlsVersion.ONE_ONE),
                            new ClusterInner()
                                .withLocation("thwxmnteiwaopvkm")
                                .withTags(mapOf("uf", "mmxdcu"))
                                .withSku(new Sku().withName(SkuName.ENTERPRISE_FLASH_F1500).withCapacity(19976049))
                                .withZones(Arrays.asList("bvpyss", "dnrujqguhmuouqfp", "wzwbnguitn"))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withMinimumTlsVersion(TlsVersion.ONE_ONE),
                            new ClusterInner()
                                .withLocation("wpgrjbzno")
                                .withTags(mapOf("nb", "xv", "rzafbljjgpbtoqcj", "xqabnmocpcysh", "vbqid", "klj"))
                                .withSku(new Sku().withName(SkuName.ENTERPRISE_E20).withCapacity(219333087))
                                .withZones(Arrays.asList("sfqpteehz", "vypyqrimzinpv", "wjdk"))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withMinimumTlsVersion(TlsVersion.ONE_ZERO),
                            new ClusterInner()
                                .withLocation("xgcp")
                                .withTags(mapOf("mcl", "maajrmvdjwzrlo", "jctbza", "hijco"))
                                .withSku(new Sku().withName(SkuName.ENTERPRISE_E20).withCapacity(1678385538))
                                .withZones(Arrays.asList("scpai", "rhhbcs", "l"))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withMinimumTlsVersion(TlsVersion.ONE_TWO)));
        model = BinaryData.fromObject(model).toObject(ClusterList.class);
        Assertions.assertEquals("smodmgloug", model.value().get(0).location());
        Assertions.assertEquals("wtmutduq", model.value().get(0).tags().get("ta"));
        Assertions.assertEquals(SkuName.ENTERPRISE_E100, model.value().get(0).sku().name());
        Assertions.assertEquals(757698897, model.value().get(0).sku().capacity());
        Assertions.assertEquals("l", model.value().get(0).zones().get(0));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals(TlsVersion.ONE_ONE, model.value().get(0).minimumTlsVersion());
    }

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