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

package com.azure.resourcemanager.managednetworkfabric.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.managednetworkfabric.fluent.models.NetworkDeviceInner;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkDeviceRoleTypes;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkDevicesListResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class NetworkDevicesListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        NetworkDevicesListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"version\":\"fq\",\"networkDeviceSku\":\"zgxmr\",\"networkDeviceRole\":\"ToR\",\"provisioningState\":\"Canceled\",\"networkRackId\":\"pcesutrg\",\"hostName\":\"pauutpw\",\"serialNumber\":\"hihejqgwzpnfqn\",\"annotation\":\"ypsxjvfoim\"},\"location\":\"slirciz\",\"tags\":{\"cvlhv\":\"ydfce\",\"jslb\":\"gdyftumrtwna\",\"aeqphchqnr\":\"wkojgcyztsfmzn\",\"wrykqgai\":\"rpxeh\"},\"id\":\"mvikl\",\"name\":\"ydv\",\"type\":\"hbejdznxcvdsrhnj\"},{\"properties\":{\"version\":\"lvtno\",\"networkDeviceSku\":\"qfzgemjdftul\",\"networkDeviceRole\":\"TS\",\"provisioningState\":\"Failed\",\"networkRackId\":\"ceamtm\",\"hostName\":\"u\",\"serialNumber\":\"ejwcwwqiok\",\"annotation\":\"sx\"},\"location\":\"jmsvpkjp\",\"tags\":{\"zheydbsdshmk\":\"wcfzqljyxgt\"},\"id\":\"maehvbbxurip\",\"name\":\"tfnhtbaxkgxywr\",\"type\":\"kpyklyhp\"}],\"nextLink\":\"odpvruudlgzib\"}")
                .toObject(NetworkDevicesListResult.class);
        Assertions.assertEquals("slirciz", model.value().get(0).location());
        Assertions.assertEquals("ydfce", model.value().get(0).tags().get("cvlhv"));
        Assertions.assertEquals("zgxmr", model.value().get(0).networkDeviceSku());
        Assertions.assertEquals(NetworkDeviceRoleTypes.TOR, model.value().get(0).networkDeviceRole());
        Assertions.assertEquals("pauutpw", model.value().get(0).hostname());
        Assertions.assertEquals("hihejqgwzpnfqn", model.value().get(0).serialNumber());
        Assertions.assertEquals("ypsxjvfoim", model.value().get(0).annotation());
        Assertions.assertEquals("odpvruudlgzib", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        NetworkDevicesListResult model =
            new NetworkDevicesListResult()
                .withValue(
                    Arrays
                        .asList(
                            new NetworkDeviceInner()
                                .withLocation("slirciz")
                                .withTags(
                                    mapOf(
                                        "cvlhv",
                                        "ydfce",
                                        "jslb",
                                        "gdyftumrtwna",
                                        "aeqphchqnr",
                                        "wkojgcyztsfmzn",
                                        "wrykqgai",
                                        "rpxeh"))
                                .withNetworkDeviceSku("zgxmr")
                                .withNetworkDeviceRole(NetworkDeviceRoleTypes.TOR)
                                .withHostname("pauutpw")
                                .withSerialNumber("hihejqgwzpnfqn")
                                .withAnnotation("ypsxjvfoim"),
                            new NetworkDeviceInner()
                                .withLocation("jmsvpkjp")
                                .withTags(mapOf("zheydbsdshmk", "wcfzqljyxgt"))
                                .withNetworkDeviceSku("qfzgemjdftul")
                                .withNetworkDeviceRole(NetworkDeviceRoleTypes.TS)
                                .withHostname("u")
                                .withSerialNumber("ejwcwwqiok")
                                .withAnnotation("sx")))
                .withNextLink("odpvruudlgzib");
        model = BinaryData.fromObject(model).toObject(NetworkDevicesListResult.class);
        Assertions.assertEquals("slirciz", model.value().get(0).location());
        Assertions.assertEquals("ydfce", model.value().get(0).tags().get("cvlhv"));
        Assertions.assertEquals("zgxmr", model.value().get(0).networkDeviceSku());
        Assertions.assertEquals(NetworkDeviceRoleTypes.TOR, model.value().get(0).networkDeviceRole());
        Assertions.assertEquals("pauutpw", model.value().get(0).hostname());
        Assertions.assertEquals("hihejqgwzpnfqn", model.value().get(0).serialNumber());
        Assertions.assertEquals("ypsxjvfoim", model.value().get(0).annotation());
        Assertions.assertEquals("odpvruudlgzib", model.nextLink());
    }

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