// 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.IpPrefixInner;
import com.azure.resourcemanager.managednetworkfabric.models.IpPrefixesListResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class IpPrefixesListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IpPrefixesListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"ipPrefixRules\":[],\"provisioningState\":\"Failed\",\"annotation\":\"pulexxbczw\"},\"location\":\"uwiqzb\",\"tags\":{\"zdobpxjmflbvvnch\":\"sovmyokacspkwl\",\"ajiwkuo\":\"kcciwwzjuqkhr\",\"sauuimj\":\"oskg\"},\"id\":\"vxieduugidyj\",\"name\":\"rfbyaosvexcso\",\"type\":\"pclhocohslk\"}],\"nextLink\":\"leggzfbu\"}")
                .toObject(IpPrefixesListResult.class);
        Assertions.assertEquals("uwiqzb", model.value().get(0).location());
        Assertions.assertEquals("sovmyokacspkwl", model.value().get(0).tags().get("zdobpxjmflbvvnch"));
        Assertions.assertEquals("pulexxbczw", model.value().get(0).annotation());
        Assertions.assertEquals("leggzfbu", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IpPrefixesListResult model =
            new IpPrefixesListResult()
                .withValue(
                    Arrays
                        .asList(
                            new IpPrefixInner()
                                .withLocation("uwiqzb")
                                .withTags(
                                    mapOf(
                                        "zdobpxjmflbvvnch",
                                        "sovmyokacspkwl",
                                        "ajiwkuo",
                                        "kcciwwzjuqkhr",
                                        "sauuimj",
                                        "oskg"))
                                .withIpPrefixRules(Arrays.asList())
                                .withAnnotation("pulexxbczw")))
                .withNextLink("leggzfbu");
        model = BinaryData.fromObject(model).toObject(IpPrefixesListResult.class);
        Assertions.assertEquals("uwiqzb", model.value().get(0).location());
        Assertions.assertEquals("sovmyokacspkwl", model.value().get(0).tags().get("zdobpxjmflbvvnch"));
        Assertions.assertEquals("pulexxbczw", model.value().get(0).annotation());
        Assertions.assertEquals("leggzfbu", 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;
    }
}
