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

package com.azure.resourcemanager.hybridnetwork.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.hybridnetwork.fluent.models.DeviceInner;
import com.azure.resourcemanager.hybridnetwork.models.DeviceListResult;
import com.azure.resourcemanager.hybridnetwork.models.DevicePropertiesFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class DeviceListResultTests {
    @Test
    public void testDeserialize() {
        DeviceListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"deviceType\":\"DevicePropertiesFormat\",\"status\":\"Deleted\",\"provisioningState\":\"Unknown\",\"networkFunctions\":[]},\"location\":\"thqt\",\"tags\":{\"zfsinzgvf\":\"jbp\",\"j\":\"jrwzox\",\"fpjkjlxofp\":\"felluwfzitonpe\"},\"id\":\"vhpfxxypininmay\",\"name\":\"uybbkpodep\",\"type\":\"oginuvamiheognar\"},{\"properties\":{\"deviceType\":\"DevicePropertiesFormat\",\"status\":\"Registered\",\"provisioningState\":\"Deleting\",\"networkFunctions\":[]},\"location\":\"usivye\",\"tags\":{\"un\":\"iqihn\",\"fygxgispemvtzfk\":\"bwjzr\",\"fxqeof\":\"fublj\"},\"id\":\"aeqjhqjbasvms\",\"name\":\"jqul\",\"type\":\"gsntnbybkzgcwr\"},{\"properties\":{\"deviceType\":\"DevicePropertiesFormat\",\"status\":\"Unknown\",\"provisioningState\":\"Succeeded\",\"networkFunctions\":[]},\"location\":\"jdous\",\"tags\":{\"xbnjbiksq\":\"vkocrcjdkwtn\",\"ainqpjwnzlljfm\":\"gls\"},\"id\":\"pee\",\"name\":\"vmgxsab\",\"type\":\"yqduujit\"}],\"nextLink\":\"czdzev\"}")
                .toObject(DeviceListResult.class);
        Assertions.assertEquals("thqt", model.value().get(0).location());
        Assertions.assertEquals("jbp", model.value().get(0).tags().get("zfsinzgvf"));
    }

    @Test
    public void testSerialize() {
        DeviceListResult model =
            new DeviceListResult()
                .withValue(
                    Arrays
                        .asList(
                            new DeviceInner()
                                .withLocation("thqt")
                                .withTags(mapOf("zfsinzgvf", "jbp", "j", "jrwzox", "fpjkjlxofp", "felluwfzitonpe"))
                                .withProperties(new DevicePropertiesFormat()),
                            new DeviceInner()
                                .withLocation("usivye")
                                .withTags(mapOf("un", "iqihn", "fygxgispemvtzfk", "bwjzr", "fxqeof", "fublj"))
                                .withProperties(new DevicePropertiesFormat()),
                            new DeviceInner()
                                .withLocation("jdous")
                                .withTags(mapOf("xbnjbiksq", "vkocrcjdkwtn", "ainqpjwnzlljfm", "gls"))
                                .withProperties(new DevicePropertiesFormat())));
        model = BinaryData.fromObject(model).toObject(DeviceListResult.class);
        Assertions.assertEquals("thqt", model.value().get(0).location());
        Assertions.assertEquals("jbp", model.value().get(0).tags().get("zfsinzgvf"));
    }

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