// 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.CreateMode;
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 ConfigurationStoreInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ConfigurationStoreInner model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"o\":{\"principalId\":\"pjoxzjnch\",\"clientId\":\"jspodmailzyde\"}},\"principalId\":\"yahux\",\"tenantId\":\"pmqnja\"},\"properties\":{\"provisioningState\":\"Deleting\",\"creationDate\":\"2021-08-22T00:38:37Z\",\"endpoint\":\"r\",\"encryption\":{},\"privateEndpointConnections\":[{\"id\":\"tegjvwmf\",\"name\":\"t\",\"type\":\"mdvpjhulsu\"},{\"id\":\"kjozkrwfnd\",\"name\":\"djpslw\",\"type\":\"dpvwryoqpsoaccta\"},{\"id\":\"ljlahbcryf\",\"name\":\"fdosyg\",\"type\":\"paojakhmsbzjh\"}],\"publicNetworkAccess\":\"Disabled\",\"disableLocalAuth\":true,\"softDeleteRetentionInDays\":656929943,\"enablePurgeProtection\":false,\"createMode\":\"Default\"},\"sku\":{\"name\":\"lthqtrgqjbp\"},\"location\":\"fsinzgvfcjrwzoxx\",\"tags\":{\"eqfpj\":\"elluwfziton\",\"ninmayhuyb\":\"jlxofpdvhpfxxyp\",\"ooginuvamih\":\"kpode\",\"vyevcciqi\":\"ognarxzxtheotus\"},\"id\":\"nhungbw\",\"name\":\"zrnf\",\"type\":\"gxg\"}")
                .toObject(ConfigurationStoreInner.class);
        Assertions.assertEquals("fsinzgvfcjrwzoxx", model.location());
        Assertions.assertEquals("elluwfziton", model.tags().get("eqfpj"));
        Assertions.assertEquals(IdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("lthqtrgqjbp", model.sku().name());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.publicNetworkAccess());
        Assertions.assertEquals(true, model.disableLocalAuth());
        Assertions.assertEquals(656929943, model.softDeleteRetentionInDays());
        Assertions.assertEquals(false, model.enablePurgeProtection());
        Assertions.assertEquals(CreateMode.DEFAULT, model.createMode());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ConfigurationStoreInner model =
            new ConfigurationStoreInner()
                .withLocation("fsinzgvfcjrwzoxx")
                .withTags(
                    mapOf(
                        "eqfpj",
                        "elluwfziton",
                        "ninmayhuyb",
                        "jlxofpdvhpfxxyp",
                        "ooginuvamih",
                        "kpode",
                        "vyevcciqi",
                        "ognarxzxtheotus"))
                .withIdentity(
                    new ResourceIdentity()
                        .withType(IdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(mapOf("o", new UserIdentity())))
                .withSku(new Sku().withName("lthqtrgqjbp"))
                .withEncryption(new EncryptionProperties())
                .withPublicNetworkAccess(PublicNetworkAccess.DISABLED)
                .withDisableLocalAuth(true)
                .withSoftDeleteRetentionInDays(656929943)
                .withEnablePurgeProtection(false)
                .withCreateMode(CreateMode.DEFAULT);
        model = BinaryData.fromObject(model).toObject(ConfigurationStoreInner.class);
        Assertions.assertEquals("fsinzgvfcjrwzoxx", model.location());
        Assertions.assertEquals("elluwfziton", model.tags().get("eqfpj"));
        Assertions.assertEquals(IdentityType.USER_ASSIGNED, model.identity().type());
        Assertions.assertEquals("lthqtrgqjbp", model.sku().name());
        Assertions.assertEquals(PublicNetworkAccess.DISABLED, model.publicNetworkAccess());
        Assertions.assertEquals(true, model.disableLocalAuth());
        Assertions.assertEquals(656929943, model.softDeleteRetentionInDays());
        Assertions.assertEquals(false, model.enablePurgeProtection());
        Assertions.assertEquals(CreateMode.DEFAULT, model.createMode());
    }

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