// 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.CentralServerFullResourceNames;
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 CentralServerFullResourceNamesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CentralServerFullResourceNames model =
            BinaryData
                .fromString(
                    "{\"virtualMachines\":[{\"vmName\":\"rfzeey\",\"hostName\":\"izikayuhq\",\"networkInterfaces\":[],\"osDiskName\":\"sybbqwr\",\"dataDiskNames\":{\"owqkdwytisi\":[\"gmfpgvmp\",\"paslthaqfxssmwu\",\"wbdsr\",\"zpdrhneu\"],\"iavrm\":[\"rcgp\",\"kpzi\",\"ejzanlfz\"],\"pj\":[\"onok\",\"xrjqcirgzpfrlazs\",\"rnwoiindfp\"]}}],\"availabilitySetName\":\"wbtlhflsjcdh\",\"loadBalancer\":{\"loadBalancerName\":\"jvfbgofelja\",\"frontendIpConfigurationNames\":[\"mqhldvrii\",\"ojnal\",\"hfkvtvsexsowuel\"],\"backendPoolNames\":[\"hahhxvrhmzkwpj\",\"wws\",\"ughftqsx\",\"qxujxukndxd\"],\"healthProbeNames\":[\"jguufzdm\",\"yqtfihwh\",\"otzi\",\"gamv\"]}}")
                .toObject(CentralServerFullResourceNames.class);
        Assertions.assertEquals("rfzeey", model.virtualMachines().get(0).vmName());
        Assertions.assertEquals("izikayuhq", model.virtualMachines().get(0).hostname());
        Assertions.assertEquals("sybbqwr", model.virtualMachines().get(0).osDiskName());
        Assertions.assertEquals("gmfpgvmp", model.virtualMachines().get(0).dataDiskNames().get("owqkdwytisi").get(0));
        Assertions.assertEquals("wbtlhflsjcdh", model.availabilitySetName());
        Assertions.assertEquals("jvfbgofelja", model.loadBalancer().loadBalancerName());
        Assertions.assertEquals("mqhldvrii", model.loadBalancer().frontendIpConfigurationNames().get(0));
        Assertions.assertEquals("hahhxvrhmzkwpj", model.loadBalancer().backendPoolNames().get(0));
        Assertions.assertEquals("jguufzdm", model.loadBalancer().healthProbeNames().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CentralServerFullResourceNames model =
            new CentralServerFullResourceNames()
                .withVirtualMachines(
                    Arrays
                        .asList(
                            new VirtualMachineResourceNames()
                                .withVmName("rfzeey")
                                .withHostname("izikayuhq")
                                .withNetworkInterfaces(Arrays.asList())
                                .withOsDiskName("sybbqwr")
                                .withDataDiskNames(
                                    mapOf(
                                        "owqkdwytisi",
                                        Arrays.asList("gmfpgvmp", "paslthaqfxssmwu", "wbdsr", "zpdrhneu"),
                                        "iavrm",
                                        Arrays.asList("rcgp", "kpzi", "ejzanlfz"),
                                        "pj",
                                        Arrays.asList("onok", "xrjqcirgzpfrlazs", "rnwoiindfp")))))
                .withAvailabilitySetName("wbtlhflsjcdh")
                .withLoadBalancer(
                    new LoadBalancerResourceNames()
                        .withLoadBalancerName("jvfbgofelja")
                        .withFrontendIpConfigurationNames(Arrays.asList("mqhldvrii", "ojnal", "hfkvtvsexsowuel"))
                        .withBackendPoolNames(Arrays.asList("hahhxvrhmzkwpj", "wws", "ughftqsx", "qxujxukndxd"))
                        .withHealthProbeNames(Arrays.asList("jguufzdm", "yqtfihwh", "otzi", "gamv")));
        model = BinaryData.fromObject(model).toObject(CentralServerFullResourceNames.class);
        Assertions.assertEquals("rfzeey", model.virtualMachines().get(0).vmName());
        Assertions.assertEquals("izikayuhq", model.virtualMachines().get(0).hostname());
        Assertions.assertEquals("sybbqwr", model.virtualMachines().get(0).osDiskName());
        Assertions.assertEquals("gmfpgvmp", model.virtualMachines().get(0).dataDiskNames().get("owqkdwytisi").get(0));
        Assertions.assertEquals("wbtlhflsjcdh", model.availabilitySetName());
        Assertions.assertEquals("jvfbgofelja", model.loadBalancer().loadBalancerName());
        Assertions.assertEquals("mqhldvrii", model.loadBalancer().frontendIpConfigurationNames().get(0));
        Assertions.assertEquals("hahhxvrhmzkwpj", model.loadBalancer().backendPoolNames().get(0));
        Assertions.assertEquals("jguufzdm", 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;
    }
}
