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

package com.azure.resourcemanager.servicenetworking.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.servicenetworking.fluent.models.FrontendInner;
import com.azure.resourcemanager.servicenetworking.models.FrontendListResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class FrontendListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        FrontendListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"fqdn\":\"nohjt\",\"provisioningState\":\"Accepted\"},\"location\":\"dsoifiyipj\",\"tags\":{\"cjxvsnbyxqab\":\"wpgrjbzno\",\"shurzafbljjgpbto\":\"mocpc\",\"mkljavb\":\"c\"},\"id\":\"idtqajzyu\",\"name\":\"pku\",\"type\":\"jkrlkhbzhfepg\"},{\"properties\":{\"fqdn\":\"e\",\"provisioningState\":\"Provisioning\"},\"location\":\"c\",\"tags\":{\"bcsglumma\":\"paierh\"},\"id\":\"tjaodxobnb\",\"name\":\"xkqpxo\",\"type\":\"ajionpimexgstxg\"},{\"properties\":{\"fqdn\":\"dg\",\"provisioningState\":\"Succeeded\"},\"location\":\"r\",\"tags\":{\"vmclw\":\"jwzrl\",\"aqsqsycbkbfk\":\"ijcoejctb\"},\"id\":\"ukdkexxppofmxa\",\"name\":\"c\",\"type\":\"jpgd\"},{\"properties\":{\"fqdn\":\"c\",\"provisioningState\":\"Failed\"},\"location\":\"vpmouexhdzxib\",\"tags\":{\"eic\":\"jnxqbzvddntwn\",\"cyddglmjthjqk\":\"twnpzaoqvuhrhcf\",\"ciwqvhk\":\"pyeicxm\"},\"id\":\"ixuigdtopbobj\",\"name\":\"ghmewuam\",\"type\":\"uhrzayvvt\"}],\"nextLink\":\"vdfgiotk\"}")
                .toObject(FrontendListResult.class);
        Assertions.assertEquals("dsoifiyipj", model.value().get(0).location());
        Assertions.assertEquals("wpgrjbzno", model.value().get(0).tags().get("cjxvsnbyxqab"));
        Assertions.assertEquals("vdfgiotk", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        FrontendListResult model =
            new FrontendListResult()
                .withValue(
                    Arrays
                        .asList(
                            new FrontendInner()
                                .withLocation("dsoifiyipj")
                                .withTags(
                                    mapOf("cjxvsnbyxqab", "wpgrjbzno", "shurzafbljjgpbto", "mocpc", "mkljavb", "c")),
                            new FrontendInner().withLocation("c").withTags(mapOf("bcsglumma", "paierh")),
                            new FrontendInner()
                                .withLocation("r")
                                .withTags(mapOf("vmclw", "jwzrl", "aqsqsycbkbfk", "ijcoejctb")),
                            new FrontendInner()
                                .withLocation("vpmouexhdzxib")
                                .withTags(
                                    mapOf(
                                        "eic",
                                        "jnxqbzvddntwn",
                                        "cyddglmjthjqk",
                                        "twnpzaoqvuhrhcf",
                                        "ciwqvhk",
                                        "pyeicxm"))))
                .withNextLink("vdfgiotk");
        model = BinaryData.fromObject(model).toObject(FrontendListResult.class);
        Assertions.assertEquals("dsoifiyipj", model.value().get(0).location());
        Assertions.assertEquals("wpgrjbzno", model.value().get(0).tags().get("cjxvsnbyxqab"));
        Assertions.assertEquals("vdfgiotk", 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;
    }
}
