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

public final class RoutePoliciesListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        RoutePoliciesListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"statements\":[],\"provisioningState\":\"Canceled\",\"annotation\":\"xqmul\"},\"location\":\"lxqzvn\",\"tags\":{\"brqbsmswzi\":\"bycucrwnamikz\",\"vhczznvfby\":\"gfuhokzrusw\",\"vumwmxqh\":\"jsxjwwix\",\"hflzokxco\":\"dvnoamldsehaohdj\"},\"id\":\"pelnjetag\",\"name\":\"tsxoatftgz\",\"type\":\"npbs\"},{\"properties\":{\"statements\":[],\"provisioningState\":\"Failed\",\"annotation\":\"loccsrmozihm\"},\"location\":\"g\",\"tags\":{\"xgrytfmp\":\"xxpkyjcxc\"},\"id\":\"ycilrmcaykggnox\",\"name\":\"ztrksxwpndf\",\"type\":\"pfnznthjtwkj\"},{\"properties\":{\"statements\":[],\"provisioningState\":\"Updating\",\"annotation\":\"xuzvoamktcqi\"},\"location\":\"mgbzahgxqdlyrtl\",\"tags\":{\"nbsoqeqalarv\":\"prltzkatbhjmz\"},\"id\":\"agunbtgfebw\",\"name\":\"nbmhyree\",\"type\":\"dzqavbpdqmjxlyyz\"},{\"properties\":{\"statements\":[],\"provisioningState\":\"Failed\",\"annotation\":\"uwt\"},\"location\":\"jjyuojqtobax\",\"tags\":{\"snkq\":\"ytunlbfjkwr\"},\"id\":\"hsyrqunj\",\"name\":\"hdenxaulk\",\"type\":\"akdkifmjnnawtqab\"}],\"nextLink\":\"uckpggqoweyir\"}")
                .toObject(RoutePoliciesListResult.class);
        Assertions.assertEquals("lxqzvn", model.value().get(0).location());
        Assertions.assertEquals("bycucrwnamikz", model.value().get(0).tags().get("brqbsmswzi"));
        Assertions.assertEquals("xqmul", model.value().get(0).annotation());
        Assertions.assertEquals("uckpggqoweyir", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        RoutePoliciesListResult model =
            new RoutePoliciesListResult()
                .withValue(
                    Arrays
                        .asList(
                            new RoutePolicyInner()
                                .withLocation("lxqzvn")
                                .withTags(
                                    mapOf(
                                        "brqbsmswzi",
                                        "bycucrwnamikz",
                                        "vhczznvfby",
                                        "gfuhokzrusw",
                                        "vumwmxqh",
                                        "jsxjwwix",
                                        "hflzokxco",
                                        "dvnoamldsehaohdj"))
                                .withStatements(Arrays.asList())
                                .withAnnotation("xqmul"),
                            new RoutePolicyInner()
                                .withLocation("g")
                                .withTags(mapOf("xgrytfmp", "xxpkyjcxc"))
                                .withStatements(Arrays.asList())
                                .withAnnotation("loccsrmozihm"),
                            new RoutePolicyInner()
                                .withLocation("mgbzahgxqdlyrtl")
                                .withTags(mapOf("nbsoqeqalarv", "prltzkatbhjmz"))
                                .withStatements(Arrays.asList())
                                .withAnnotation("xuzvoamktcqi"),
                            new RoutePolicyInner()
                                .withLocation("jjyuojqtobax")
                                .withTags(mapOf("snkq", "ytunlbfjkwr"))
                                .withStatements(Arrays.asList())
                                .withAnnotation("uwt")))
                .withNextLink("uckpggqoweyir");
        model = BinaryData.fromObject(model).toObject(RoutePoliciesListResult.class);
        Assertions.assertEquals("lxqzvn", model.value().get(0).location());
        Assertions.assertEquals("bycucrwnamikz", model.value().get(0).tags().get("brqbsmswzi"));
        Assertions.assertEquals("xqmul", model.value().get(0).annotation());
        Assertions.assertEquals("uckpggqoweyir", 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;
    }
}
