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

public final class AccessControlListsListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AccessControlListsListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"addressFamily\":\"ipv4\",\"conditions\":[],\"provisioningState\":\"Updating\",\"annotation\":\"ybb\"},\"location\":\"odepoogin\",\"tags\":{\"gnarxzxtheo\":\"mihe\",\"cciqihnhungbwjz\":\"usivye\",\"kufubljo\":\"nfygxgispemvtz\"},\"id\":\"xqeofjaeqjhqjba\",\"name\":\"v\",\"type\":\"smjqulngsntnbyb\"},{\"properties\":{\"addressFamily\":\"ipv4\",\"conditions\":[],\"provisioningState\":\"Failed\",\"annotation\":\"rwclxxwrljdo\"},\"location\":\"kcqvkocrc\",\"tags\":{\"lssai\":\"wtnhxbnjbiksqr\"},\"id\":\"qpjwnzlljfm\",\"name\":\"pee\",\"type\":\"vmgxsab\"},{\"properties\":{\"addressFamily\":\"ipv4\",\"conditions\":[],\"provisioningState\":\"Canceled\",\"annotation\":\"ujitcjcz\"},\"location\":\"evndh\",\"tags\":{\"dkvwrwjfe\":\"pdappds\",\"je\":\"snhu\",\"hocdgeab\":\"tmrldhugjzzdatq\"},\"id\":\"gphuticndvka\",\"name\":\"zwyiftyhxhur\",\"type\":\"k\"},{\"properties\":{\"addressFamily\":\"ipv6\",\"conditions\":[],\"provisioningState\":\"Failed\",\"annotation\":\"lniwpwcukjfkgiaw\"},\"location\":\"lryplwckbasyy\",\"tags\":{\"phejkotynqgoulz\":\"dhsgcba\",\"gakeqsr\":\"dlikwyqkgfgibma\",\"qqedqytbciqfou\":\"yb\"},\"id\":\"lmmnkzsmodmglo\",\"name\":\"gpbkwtmut\",\"type\":\"uqktap\"}],\"nextLink\":\"wgcu\"}")
                .toObject(AccessControlListsListResult.class);
        Assertions.assertEquals("odepoogin", model.value().get(0).location());
        Assertions.assertEquals("mihe", model.value().get(0).tags().get("gnarxzxtheo"));
        Assertions.assertEquals(AddressFamily.IPV4, model.value().get(0).addressFamily());
        Assertions.assertEquals("ybb", model.value().get(0).annotation());
        Assertions.assertEquals("wgcu", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AccessControlListsListResult model =
            new AccessControlListsListResult()
                .withValue(
                    Arrays
                        .asList(
                            new AccessControlListInner()
                                .withLocation("odepoogin")
                                .withTags(
                                    mapOf(
                                        "gnarxzxtheo",
                                        "mihe",
                                        "cciqihnhungbwjz",
                                        "usivye",
                                        "kufubljo",
                                        "nfygxgispemvtz"))
                                .withAddressFamily(AddressFamily.IPV4)
                                .withConditions(Arrays.asList())
                                .withAnnotation("ybb"),
                            new AccessControlListInner()
                                .withLocation("kcqvkocrc")
                                .withTags(mapOf("lssai", "wtnhxbnjbiksqr"))
                                .withAddressFamily(AddressFamily.IPV4)
                                .withConditions(Arrays.asList())
                                .withAnnotation("rwclxxwrljdo"),
                            new AccessControlListInner()
                                .withLocation("evndh")
                                .withTags(mapOf("dkvwrwjfe", "pdappds", "je", "snhu", "hocdgeab", "tmrldhugjzzdatq"))
                                .withAddressFamily(AddressFamily.IPV4)
                                .withConditions(Arrays.asList())
                                .withAnnotation("ujitcjcz"),
                            new AccessControlListInner()
                                .withLocation("lryplwckbasyy")
                                .withTags(
                                    mapOf(
                                        "phejkotynqgoulz",
                                        "dhsgcba",
                                        "gakeqsr",
                                        "dlikwyqkgfgibma",
                                        "qqedqytbciqfou",
                                        "yb"))
                                .withAddressFamily(AddressFamily.IPV6)
                                .withConditions(Arrays.asList())
                                .withAnnotation("lniwpwcukjfkgiaw")))
                .withNextLink("wgcu");
        model = BinaryData.fromObject(model).toObject(AccessControlListsListResult.class);
        Assertions.assertEquals("odepoogin", model.value().get(0).location());
        Assertions.assertEquals("mihe", model.value().get(0).tags().get("gnarxzxtheo"));
        Assertions.assertEquals(AddressFamily.IPV4, model.value().get(0).addressFamily());
        Assertions.assertEquals("ybb", model.value().get(0).annotation());
        Assertions.assertEquals("wgcu", 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;
    }
}
