// 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.DatabaseServerFullResourceNames;
import com.azure.resourcemanager.workloads.models.LoadBalancerResourceNames;
import com.azure.resourcemanager.workloads.models.VirtualMachineResourceNames;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class DatabaseServerFullResourceNamesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DatabaseServerFullResourceNames model =
            BinaryData
                .fromString(
                    "{\"virtualMachines\":[{\"vmName\":\"tmmjihyeozph\",\"hostName\":\"auyqncygupkv\",\"networkInterfaces\":[],\"osDiskName\":\"scw\",\"dataDiskNames\":{\"ypelmcu\":[\"evzhfsto\",\"xhojuj\"]}}],\"availabilitySetName\":\"ixbjx\",\"loadBalancer\":{\"loadBalancerName\":\"n\",\"frontendIpConfigurationNames\":[\"coolsttpkiwkkb\"],\"backendPoolNames\":[\"rywvtylbfpn\",\"urdoi\",\"iithtywu\",\"xcbihw\"],\"healthProbeNames\":[\"fdntwjchrdgoih\"]}}")
                .toObject(DatabaseServerFullResourceNames.class);
        Assertions.assertEquals("tmmjihyeozph", model.virtualMachines().get(0).vmName());
        Assertions.assertEquals("auyqncygupkv", model.virtualMachines().get(0).hostname());
        Assertions.assertEquals("scw", model.virtualMachines().get(0).osDiskName());
        Assertions.assertEquals("evzhfsto", model.virtualMachines().get(0).dataDiskNames().get("ypelmcu").get(0));
        Assertions.assertEquals("ixbjx", model.availabilitySetName());
        Assertions.assertEquals("n", model.loadBalancer().loadBalancerName());
        Assertions.assertEquals("coolsttpkiwkkb", model.loadBalancer().frontendIpConfigurationNames().get(0));
        Assertions.assertEquals("rywvtylbfpn", model.loadBalancer().backendPoolNames().get(0));
        Assertions.assertEquals("fdntwjchrdgoih", model.loadBalancer().healthProbeNames().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DatabaseServerFullResourceNames model =
            new DatabaseServerFullResourceNames()
                .withVirtualMachines(
                    Arrays
                        .asList(
                            new VirtualMachineResourceNames()
                                .withVmName("tmmjihyeozph")
                                .withHostname("auyqncygupkv")
                                .withNetworkInterfaces(Arrays.asList())
                                .withOsDiskName("scw")
                                .withDataDiskNames(mapOf("ypelmcu", Arrays.asList("evzhfsto", "xhojuj")))))
                .withAvailabilitySetName("ixbjx")
                .withLoadBalancer(
                    new LoadBalancerResourceNames()
                        .withLoadBalancerName("n")
                        .withFrontendIpConfigurationNames(Arrays.asList("coolsttpkiwkkb"))
                        .withBackendPoolNames(Arrays.asList("rywvtylbfpn", "urdoi", "iithtywu", "xcbihw"))
                        .withHealthProbeNames(Arrays.asList("fdntwjchrdgoih")));
        model = BinaryData.fromObject(model).toObject(DatabaseServerFullResourceNames.class);
        Assertions.assertEquals("tmmjihyeozph", model.virtualMachines().get(0).vmName());
        Assertions.assertEquals("auyqncygupkv", model.virtualMachines().get(0).hostname());
        Assertions.assertEquals("scw", model.virtualMachines().get(0).osDiskName());
        Assertions.assertEquals("evzhfsto", model.virtualMachines().get(0).dataDiskNames().get("ypelmcu").get(0));
        Assertions.assertEquals("ixbjx", model.availabilitySetName());
        Assertions.assertEquals("n", model.loadBalancer().loadBalancerName());
        Assertions.assertEquals("coolsttpkiwkkb", model.loadBalancer().frontendIpConfigurationNames().get(0));
        Assertions.assertEquals("rywvtylbfpn", model.loadBalancer().backendPoolNames().get(0));
        Assertions.assertEquals("fdntwjchrdgoih", model.loadBalancer().healthProbeNames().get(0));
    }

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