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

public final class IpCommunitiesListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IpCommunitiesListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"action\":\"Deny\",\"wellKnownCommunities\":[],\"communityMembers\":[],\"provisioningState\":\"Deleting\",\"annotation\":\"cxtbzsg\"},\"location\":\"c\",\"tags\":{\"jeiachboosfl\":\"ewmdw\",\"fqpte\":\"ro\",\"i\":\"hzzvypyq\",\"npvswjdkirso\":\"z\"},\"id\":\"dqxhcrmnohjtckwh\",\"name\":\"soifiyipjxsqw\",\"type\":\"gr\"},{\"properties\":{\"action\":\"Permit\",\"wellKnownCommunities\":[],\"communityMembers\":[],\"provisioningState\":\"Deleting\",\"annotation\":\"jxvsnbyxqabn\"},\"location\":\"cpc\",\"tags\":{\"jjgpb\":\"urzafb\",\"jmkljavbqidtqajz\":\"oq\",\"hbzhfepg\":\"ulpkudjkrl\"},\"id\":\"gqexzlocxs\",\"name\":\"paierh\",\"type\":\"bcsglumma\"},{\"properties\":{\"action\":\"Permit\",\"wellKnownCommunities\":[],\"communityMembers\":[],\"provisioningState\":\"Deleting\",\"annotation\":\"obnbdxkqpxokaj\"},\"location\":\"npime\",\"tags\":{\"vdjwzrlovm\":\"txgcpodgmaajr\",\"qsycbkbfkgu\":\"lwhijcoejctbzaq\"},\"id\":\"dkexxppofm\",\"name\":\"axcfjpgddtocjjx\",\"type\":\"vpmouexhdzxib\"},{\"properties\":{\"action\":\"Deny\",\"wellKnownCommunities\":[],\"communityMembers\":[],\"provisioningState\":\"Succeeded\",\"annotation\":\"bzv\"},\"location\":\"ntwndeicbtwnpzao\",\"tags\":{\"qkwpyeicxmqc\":\"hrhcffcyddglmjth\",\"pbobjo\":\"wqvhkhixuigdt\",\"w\":\"hm\",\"a\":\"a\"},\"id\":\"hrzayvvtpgvdf\",\"name\":\"iotkftutqxl\",\"type\":\"gxlefgugnxkrxd\"}],\"nextLink\":\"i\"}")
                .toObject(IpCommunitiesListResult.class);
        Assertions.assertEquals("c", model.value().get(0).location());
        Assertions.assertEquals("ewmdw", model.value().get(0).tags().get("jeiachboosfl"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.value().get(0).action());
        Assertions.assertEquals("cxtbzsg", model.value().get(0).annotation());
        Assertions.assertEquals("i", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IpCommunitiesListResult model =
            new IpCommunitiesListResult()
                .withValue(
                    Arrays
                        .asList(
                            new IpCommunityInner()
                                .withLocation("c")
                                .withTags(
                                    mapOf("jeiachboosfl", "ewmdw", "fqpte", "ro", "i", "hzzvypyq", "npvswjdkirso", "z"))
                                .withAction(CommunityActionTypes.DENY)
                                .withWellKnownCommunities(Arrays.asList())
                                .withCommunityMembers(Arrays.asList())
                                .withAnnotation("cxtbzsg"),
                            new IpCommunityInner()
                                .withLocation("cpc")
                                .withTags(mapOf("jjgpb", "urzafb", "jmkljavbqidtqajz", "oq", "hbzhfepg", "ulpkudjkrl"))
                                .withAction(CommunityActionTypes.PERMIT)
                                .withWellKnownCommunities(Arrays.asList())
                                .withCommunityMembers(Arrays.asList())
                                .withAnnotation("jxvsnbyxqabn"),
                            new IpCommunityInner()
                                .withLocation("npime")
                                .withTags(mapOf("vdjwzrlovm", "txgcpodgmaajr", "qsycbkbfkgu", "lwhijcoejctbzaq"))
                                .withAction(CommunityActionTypes.PERMIT)
                                .withWellKnownCommunities(Arrays.asList())
                                .withCommunityMembers(Arrays.asList())
                                .withAnnotation("obnbdxkqpxokaj"),
                            new IpCommunityInner()
                                .withLocation("ntwndeicbtwnpzao")
                                .withTags(
                                    mapOf(
                                        "qkwpyeicxmqc",
                                        "hrhcffcyddglmjth",
                                        "pbobjo",
                                        "wqvhkhixuigdt",
                                        "w",
                                        "hm",
                                        "a",
                                        "a"))
                                .withAction(CommunityActionTypes.DENY)
                                .withWellKnownCommunities(Arrays.asList())
                                .withCommunityMembers(Arrays.asList())
                                .withAnnotation("bzv")))
                .withNextLink("i");
        model = BinaryData.fromObject(model).toObject(IpCommunitiesListResult.class);
        Assertions.assertEquals("c", model.value().get(0).location());
        Assertions.assertEquals("ewmdw", model.value().get(0).tags().get("jeiachboosfl"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.value().get(0).action());
        Assertions.assertEquals("cxtbzsg", model.value().get(0).annotation());
        Assertions.assertEquals("i", 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;
    }
}
