// 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.models.ConfigurationStoreUpdateParameters;
import com.azure.resourcemanager.appconfiguration.models.EncryptionProperties;
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 com.azure.resourcemanager.appconfiguration.models.UserIdentity;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ConfigurationStoreUpdateParametersTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ConfigurationStoreUpdateParameters model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"encryption\":{},\"disableLocalAuth\":false,\"publicNetworkAccess\":\"Disabled\",\"enablePurgeProtection\":true},\"identity\":{\"type\":\"None\",\"userAssignedIdentities\":{\"uqktap\":{\"principalId\":\"mmnkzsmodmgl\",\"clientId\":\"gpbkwtmut\"},\"gbbjfddgmbmbe\":{\"principalId\":\"wgcu\",\"clientId\":\"tumkdosvqwhbm\"}},\"principalId\":\"pbhtqqrolfpfpsa\",\"tenantId\":\"bquxigjy\"},\"sku\":{\"name\":\"zjaoyfhrtxil\"},\"tags\":{\"wrlyxwjkcprb\":\"kujysvlejuvfq\",\"vpys\":\"wbxgjvt\"}}")
                .toObject(ConfigurationStoreUpdateParameters.class);
        Assertions.assertEquals(IdentityType.NONE, model.identity().type());
        Assertions.assertEquals("zjaoyfhrtxil", model.sku().name());
        Assertions.assertEquals("kujysvlejuvfq", model.tags().get("wrlyxwjkcprb"));
        Assertions.assertEquals(false, model.disableLocalAuth());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.publicNetworkAccess());
        Assertions.assertEquals(true, model.enablePurgeProtection());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ConfigurationStoreUpdateParameters model =
            new ConfigurationStoreUpdateParameters()
                .withIdentity(
                    new ResourceIdentity()
                        .withType(IdentityType.NONE)
                        .withUserAssignedIdentities(
                            mapOf("uqktap", new UserIdentity(), "gbbjfddgmbmbe", new UserIdentity())))
                .withSku(new Sku().withName("zjaoyfhrtxil"))
                .withTags(mapOf("wrlyxwjkcprb", "kujysvlejuvfq", "vpys", "wbxgjvt"))
                .withEncryption(new EncryptionProperties())
                .withDisableLocalAuth(false)
                .withPublicNetworkAccess(PublicNetworkAccess.DISABLED)
                .withEnablePurgeProtection(true);
        model = BinaryData.fromObject(model).toObject(ConfigurationStoreUpdateParameters.class);
        Assertions.assertEquals(IdentityType.NONE, model.identity().type());
        Assertions.assertEquals("zjaoyfhrtxil", model.sku().name());
        Assertions.assertEquals("kujysvlejuvfq", model.tags().get("wrlyxwjkcprb"));
        Assertions.assertEquals(false, model.disableLocalAuth());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.publicNetworkAccess());
        Assertions.assertEquals(true, model.enablePurgeProtection());
    }

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