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

package com.azure.resourcemanager.workloads.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.workloads.models.ApplicationServerConfiguration;
import com.azure.resourcemanager.workloads.models.CentralServerConfiguration;
import com.azure.resourcemanager.workloads.models.DatabaseConfiguration;
import com.azure.resourcemanager.workloads.models.DiskConfiguration;
import com.azure.resourcemanager.workloads.models.FileShareConfiguration;
import com.azure.resourcemanager.workloads.models.HighAvailabilityConfiguration;
import com.azure.resourcemanager.workloads.models.NetworkConfiguration;
import com.azure.resourcemanager.workloads.models.SapDatabaseType;
import com.azure.resourcemanager.workloads.models.SapHighAvailabilityType;
import com.azure.resourcemanager.workloads.models.StorageConfiguration;
import com.azure.resourcemanager.workloads.models.ThreeTierConfiguration;
import com.azure.resourcemanager.workloads.models.ThreeTierCustomResourceNames;
import com.azure.resourcemanager.workloads.models.VirtualMachineConfiguration;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ThreeTierConfigurationTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ThreeTierConfiguration model =
            BinaryData
                .fromString(
                    "{\"deploymentType\":\"ThreeTier\",\"networkConfiguration\":{\"isSecondaryIpEnabled\":false},\"centralServer\":{\"subnetId\":\"pulpqblylsyxk\",\"virtualMachineConfiguration\":{\"vmSize\":\"jnsjervtiagxsd\"},\"instanceCount\":1291290959009471574},\"applicationServer\":{\"subnetId\":\"e\",\"virtualMachineConfiguration\":{\"vmSize\":\"psbzkfzbeyvpn\"},\"instanceCount\":3787214015941911197},\"databaseServer\":{\"databaseType\":\"DB2\",\"subnetId\":\"nvkjjxdxrbuukzcl\",\"virtualMachineConfiguration\":{\"vmSize\":\"wyhmlw\"},\"instanceCount\":4136836492530491965,\"diskConfiguration\":{\"diskVolumeConfigurations\":{}}},\"highAvailabilityConfig\":{\"highAvailabilityType\":\"AvailabilitySet\"},\"storageConfiguration\":{\"transportFileShareConfiguration\":{\"configurationType\":\"FileShareConfiguration\"}},\"customResourceNames\":{\"namingPatternType\":\"ThreeTierCustomResourceNames\"},\"appResourceGroup\":\"kwyfzqwhxxbuyqax\"}")
                .toObject(ThreeTierConfiguration.class);
        Assertions.assertEquals("kwyfzqwhxxbuyqax", model.appResourceGroup());
        Assertions.assertEquals(false, model.networkConfiguration().isSecondaryIpEnabled());
        Assertions.assertEquals("pulpqblylsyxk", model.centralServer().subnetId());
        Assertions.assertEquals("jnsjervtiagxsd", model.centralServer().virtualMachineConfiguration().vmSize());
        Assertions.assertEquals(1291290959009471574L, model.centralServer().instanceCount());
        Assertions.assertEquals("e", model.applicationServer().subnetId());
        Assertions.assertEquals("psbzkfzbeyvpn", model.applicationServer().virtualMachineConfiguration().vmSize());
        Assertions.assertEquals(3787214015941911197L, model.applicationServer().instanceCount());
        Assertions.assertEquals(SapDatabaseType.DB2, model.databaseServer().databaseType());
        Assertions.assertEquals("nvkjjxdxrbuukzcl", model.databaseServer().subnetId());
        Assertions.assertEquals("wyhmlw", model.databaseServer().virtualMachineConfiguration().vmSize());
        Assertions.assertEquals(4136836492530491965L, model.databaseServer().instanceCount());
        Assertions
            .assertEquals(
                SapHighAvailabilityType.AVAILABILITY_SET, model.highAvailabilityConfig().highAvailabilityType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ThreeTierConfiguration model =
            new ThreeTierConfiguration()
                .withAppResourceGroup("kwyfzqwhxxbuyqax")
                .withNetworkConfiguration(new NetworkConfiguration().withIsSecondaryIpEnabled(false))
                .withCentralServer(
                    new CentralServerConfiguration()
                        .withSubnetId("pulpqblylsyxk")
                        .withVirtualMachineConfiguration(new VirtualMachineConfiguration().withVmSize("jnsjervtiagxsd"))
                        .withInstanceCount(1291290959009471574L))
                .withApplicationServer(
                    new ApplicationServerConfiguration()
                        .withSubnetId("e")
                        .withVirtualMachineConfiguration(new VirtualMachineConfiguration().withVmSize("psbzkfzbeyvpn"))
                        .withInstanceCount(3787214015941911197L))
                .withDatabaseServer(
                    new DatabaseConfiguration()
                        .withDatabaseType(SapDatabaseType.DB2)
                        .withSubnetId("nvkjjxdxrbuukzcl")
                        .withVirtualMachineConfiguration(new VirtualMachineConfiguration().withVmSize("wyhmlw"))
                        .withInstanceCount(4136836492530491965L)
                        .withDiskConfiguration(new DiskConfiguration().withDiskVolumeConfigurations(mapOf())))
                .withHighAvailabilityConfig(
                    new HighAvailabilityConfiguration()
                        .withHighAvailabilityType(SapHighAvailabilityType.AVAILABILITY_SET))
                .withStorageConfiguration(
                    new StorageConfiguration().withTransportFileShareConfiguration(new FileShareConfiguration()))
                .withCustomResourceNames(new ThreeTierCustomResourceNames());
        model = BinaryData.fromObject(model).toObject(ThreeTierConfiguration.class);
        Assertions.assertEquals("kwyfzqwhxxbuyqax", model.appResourceGroup());
        Assertions.assertEquals(false, model.networkConfiguration().isSecondaryIpEnabled());
        Assertions.assertEquals("pulpqblylsyxk", model.centralServer().subnetId());
        Assertions.assertEquals("jnsjervtiagxsd", model.centralServer().virtualMachineConfiguration().vmSize());
        Assertions.assertEquals(1291290959009471574L, model.centralServer().instanceCount());
        Assertions.assertEquals("e", model.applicationServer().subnetId());
        Assertions.assertEquals("psbzkfzbeyvpn", model.applicationServer().virtualMachineConfiguration().vmSize());
        Assertions.assertEquals(3787214015941911197L, model.applicationServer().instanceCount());
        Assertions.assertEquals(SapDatabaseType.DB2, model.databaseServer().databaseType());
        Assertions.assertEquals("nvkjjxdxrbuukzcl", model.databaseServer().subnetId());
        Assertions.assertEquals("wyhmlw", model.databaseServer().virtualMachineConfiguration().vmSize());
        Assertions.assertEquals(4136836492530491965L, model.databaseServer().instanceCount());
        Assertions
            .assertEquals(
                SapHighAvailabilityType.AVAILABILITY_SET, model.highAvailabilityConfig().highAvailabilityType());
    }

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