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

package com.azure.resourcemanager.appconfiguration.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.appconfiguration.fluent.models.ConfigurationStoreInner;
import com.azure.resourcemanager.appconfiguration.models.ConfigurationStoreListResult;
import com.azure.resourcemanager.appconfiguration.models.CreateMode;
import com.azure.resourcemanager.appconfiguration.models.IdentityType;
import com.azure.resourcemanager.appconfiguration.models.PublicNetworkAccess;
import com.azure.resourcemanager.appconfiguration.models.ResourceIdentity;
import com.azure.resourcemanager.appconfiguration.models.Sku;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ConfigurationStoreListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ConfigurationStoreListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{},\"principalId\":\"jxpybczmeh\",\"tenantId\":\"zopbsphrupidgs\"},\"properties\":{\"provisioningState\":\"Succeeded\",\"creationDate\":\"2021-10-09T17:42:33Z\",\"endpoint\":\"hoycm\",\"privateEndpointConnections\":[],\"publicNetworkAccess\":\"Enabled\",\"disableLocalAuth\":true,\"softDeleteRetentionInDays\":1615603178,\"enablePurgeProtection\":false,\"createMode\":\"Recover\"},\"sku\":{\"name\":\"oqjzehtbmufpowno\"},\"location\":\"hwlrx\",\"tags\":{\"dmbpazlobcufpdz\":\"soqijg\",\"qqjnqgl\":\"rbt\",\"foooj\":\"qgn\"},\"id\":\"wifsq\",\"name\":\"saagdf\",\"type\":\"glzlhjxrifkwmrv\"},{\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{},\"principalId\":\"to\",\"tenantId\":\"pa\"},\"properties\":{\"provisioningState\":\"Failed\",\"creationDate\":\"2021-05-16T08:34:45Z\",\"endpoint\":\"ucmpoyfd\",\"privateEndpointConnections\":[],\"publicNetworkAccess\":\"Disabled\",\"disableLocalAuth\":false,\"softDeleteRetentionInDays\":1139572680,\"enablePurgeProtection\":false,\"createMode\":\"Default\"},\"sku\":{\"name\":\"deqsrdeupewn\"},\"location\":\"eitjz\",\"tags\":{\"hs\":\"usarhmofc\",\"xukcdmpar\":\"yurkdtmlxhekuksj\"},\"id\":\"ryuanzwuxzdxtay\",\"name\":\"lhmwhfpmrqobm\",\"type\":\"u\"},{\"identity\":{\"type\":\"SystemAssigned,"
                        + " UserAssigned\",\"userAssignedIdentities\":{},\"principalId\":\"tihfx\",\"tenantId\":\"jbpzvgnwzsymg\"},\"properties\":{\"provisioningState\":\"Deleting\",\"creationDate\":\"2021-01-28T09:29:32Z\",\"endpoint\":\"kohdbiha\",\"privateEndpointConnections\":[],\"publicNetworkAccess\":\"Disabled\",\"disableLocalAuth\":false,\"softDeleteRetentionInDays\":43632750,\"enablePurgeProtection\":false,\"createMode\":\"Default\"},\"sku\":{\"name\":\"th\"},\"location\":\"hab\",\"tags\":{\"byscnp\":\"ikxwc\",\"hiv\":\"x\",\"rtfw\":\"qniwbybrkxvdumj\",\"cs\":\"ukxgaud\"},\"id\":\"h\",\"name\":\"jcny\",\"type\":\"j\"}],\"nextLink\":\"ryhtnapczwlokjy\"}")
                .toObject(ConfigurationStoreListResult.class);
        Assertions.assertEquals("hwlrx", model.value().get(0).location());
        Assertions.assertEquals("soqijg", model.value().get(0).tags().get("dmbpazlobcufpdz"));
        Assertions.assertEquals(IdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals("oqjzehtbmufpowno", model.value().get(0).sku().name());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(true, model.value().get(0).disableLocalAuth());
        Assertions.assertEquals(1615603178, model.value().get(0).softDeleteRetentionInDays());
        Assertions.assertEquals(false, model.value().get(0).enablePurgeProtection());
        Assertions.assertEquals(CreateMode.RECOVER, model.value().get(0).createMode());
        Assertions.assertEquals("ryhtnapczwlokjy", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ConfigurationStoreListResult model =
            new ConfigurationStoreListResult()
                .withValue(
                    Arrays
                        .asList(
                            new ConfigurationStoreInner()
                                .withLocation("hwlrx")
                                .withTags(mapOf("dmbpazlobcufpdz", "soqijg", "qqjnqgl", "rbt", "foooj", "qgn"))
                                .withIdentity(
                                    new ResourceIdentity()
                                        .withType(IdentityType.NONE)
                                        .withUserAssignedIdentities(mapOf()))
                                .withSku(new Sku().withName("oqjzehtbmufpowno"))
                                .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                                .withDisableLocalAuth(true)
                                .withSoftDeleteRetentionInDays(1615603178)
                                .withEnablePurgeProtection(false)
                                .withCreateMode(CreateMode.RECOVER),
                            new ConfigurationStoreInner()
                                .withLocation("eitjz")
                                .withTags(mapOf("hs", "usarhmofc", "xukcdmpar", "yurkdtmlxhekuksj"))
                                .withIdentity(
                                    new ResourceIdentity()
                                        .withType(IdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withSku(new Sku().withName("deqsrdeupewn"))
                                .withPublicNetworkAccess(PublicNetworkAccess.DISABLED)
                                .withDisableLocalAuth(false)
                                .withSoftDeleteRetentionInDays(1139572680)
                                .withEnablePurgeProtection(false)
                                .withCreateMode(CreateMode.DEFAULT),
                            new ConfigurationStoreInner()
                                .withLocation("hab")
                                .withTags(
                                    mapOf("byscnp", "ikxwc", "hiv", "x", "rtfw", "qniwbybrkxvdumj", "cs", "ukxgaud"))
                                .withIdentity(
                                    new ResourceIdentity()
                                        .withType(IdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withSku(new Sku().withName("th"))
                                .withPublicNetworkAccess(PublicNetworkAccess.DISABLED)
                                .withDisableLocalAuth(false)
                                .withSoftDeleteRetentionInDays(43632750)
                                .withEnablePurgeProtection(false)
                                .withCreateMode(CreateMode.DEFAULT)))
                .withNextLink("ryhtnapczwlokjy");
        model = BinaryData.fromObject(model).toObject(ConfigurationStoreListResult.class);
        Assertions.assertEquals("hwlrx", model.value().get(0).location());
        Assertions.assertEquals("soqijg", model.value().get(0).tags().get("dmbpazlobcufpdz"));
        Assertions.assertEquals(IdentityType.NONE, model.value().get(0).identity().type());
        Assertions.assertEquals("oqjzehtbmufpowno", model.value().get(0).sku().name());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.value().get(0).publicNetworkAccess());
        Assertions.assertEquals(true, model.value().get(0).disableLocalAuth());
        Assertions.assertEquals(1615603178, model.value().get(0).softDeleteRetentionInDays());
        Assertions.assertEquals(false, model.value().get(0).enablePurgeProtection());
        Assertions.assertEquals(CreateMode.RECOVER, model.value().get(0).createMode());
        Assertions.assertEquals("ryhtnapczwlokjy", 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;
    }
}
