// 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.NetworkInterfaceResourceNames;
import com.azure.resourcemanager.workloads.models.SingleServerFullResourceNames;
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 SingleServerFullResourceNamesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SingleServerFullResourceNames model =
            BinaryData
                .fromString(
                    "{\"namingPatternType\":\"FullResourceName\",\"virtualMachine\":{\"vmName\":\"qztpp\",\"hostName\":\"o\",\"networkInterfaces\":[{\"networkInterfaceName\":\"jaltolmnc\"}],\"osDiskName\":\"obqwcsdbnwdcfh\",\"dataDiskNames\":{\"t\":[\"pfuvglsbjjca\",\"vxb\"],\"xqtvcofu\":[\"dut\",\"cormr\"],\"gdknnqv\":[\"lvkgju\"],\"s\":[\"znqntoru\",\"sgsahmkycgr\",\"uwjuetaeburuvdmo\"]}}}")
                .toObject(SingleServerFullResourceNames.class);
        Assertions.assertEquals("qztpp", model.virtualMachine().vmName());
        Assertions.assertEquals("o", model.virtualMachine().hostname());
        Assertions.assertEquals("jaltolmnc", model.virtualMachine().networkInterfaces().get(0).networkInterfaceName());
        Assertions.assertEquals("obqwcsdbnwdcfh", model.virtualMachine().osDiskName());
        Assertions.assertEquals("pfuvglsbjjca", model.virtualMachine().dataDiskNames().get("t").get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SingleServerFullResourceNames model =
            new SingleServerFullResourceNames()
                .withVirtualMachine(
                    new VirtualMachineResourceNames()
                        .withVmName("qztpp")
                        .withHostname("o")
                        .withNetworkInterfaces(
                            Arrays.asList(new NetworkInterfaceResourceNames().withNetworkInterfaceName("jaltolmnc")))
                        .withOsDiskName("obqwcsdbnwdcfh")
                        .withDataDiskNames(
                            mapOf(
                                "t",
                                Arrays.asList("pfuvglsbjjca", "vxb"),
                                "xqtvcofu",
                                Arrays.asList("dut", "cormr"),
                                "gdknnqv",
                                Arrays.asList("lvkgju"),
                                "s",
                                Arrays.asList("znqntoru", "sgsahmkycgr", "uwjuetaeburuvdmo"))));
        model = BinaryData.fromObject(model).toObject(SingleServerFullResourceNames.class);
        Assertions.assertEquals("qztpp", model.virtualMachine().vmName());
        Assertions.assertEquals("o", model.virtualMachine().hostname());
        Assertions.assertEquals("jaltolmnc", model.virtualMachine().networkInterfaces().get(0).networkInterfaceName());
        Assertions.assertEquals("obqwcsdbnwdcfh", model.virtualMachine().osDiskName());
        Assertions.assertEquals("pfuvglsbjjca", model.virtualMachine().dataDiskNames().get("t").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;
    }
}
