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

public final class IpExtendedCommunityListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IpExtendedCommunityListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"action\":\"Deny\",\"routeTargets\":[],\"provisioningState\":\"Deleting\",\"annotation\":\"oflokey\"},\"location\":\"enjbdlwtgrhp\",\"tags\":{\"zj\":\"jumasx\"},\"id\":\"qyeg\",\"name\":\"alhbx\",\"type\":\"hejjz\"},{\"properties\":{\"action\":\"Deny\",\"routeTargets\":[],\"provisioningState\":\"Succeeded\",\"annotation\":\"wdslfhotwmcy\"},\"location\":\"wlbjnpgacftade\",\"tags\":{\"usue\":\"ltyfsop\",\"orxzdmohctbqvud\":\"nzwdejba\",\"nvowgujju\":\"xdn\",\"zj\":\"wdkcglhsl\"},\"id\":\"yggdtjixh\",\"name\":\"kuofqweykhme\",\"type\":\"evfyexfwhybcib\"}],\"nextLink\":\"vdcsitynn\"}")
                .toObject(IpExtendedCommunityListResult.class);
        Assertions.assertEquals("enjbdlwtgrhp", model.value().get(0).location());
        Assertions.assertEquals("jumasx", model.value().get(0).tags().get("zj"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.value().get(0).action());
        Assertions.assertEquals("oflokey", model.value().get(0).annotation());
        Assertions.assertEquals("vdcsitynn", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IpExtendedCommunityListResult model =
            new IpExtendedCommunityListResult()
                .withValue(
                    Arrays
                        .asList(
                            new IpExtendedCommunityInner()
                                .withLocation("enjbdlwtgrhp")
                                .withTags(mapOf("zj", "jumasx"))
                                .withAction(CommunityActionTypes.DENY)
                                .withRouteTargets(Arrays.asList())
                                .withAnnotation("oflokey"),
                            new IpExtendedCommunityInner()
                                .withLocation("wlbjnpgacftade")
                                .withTags(
                                    mapOf(
                                        "usue",
                                        "ltyfsop",
                                        "orxzdmohctbqvud",
                                        "nzwdejba",
                                        "nvowgujju",
                                        "xdn",
                                        "zj",
                                        "wdkcglhsl"))
                                .withAction(CommunityActionTypes.DENY)
                                .withRouteTargets(Arrays.asList())
                                .withAnnotation("wdslfhotwmcy")))
                .withNextLink("vdcsitynn");
        model = BinaryData.fromObject(model).toObject(IpExtendedCommunityListResult.class);
        Assertions.assertEquals("enjbdlwtgrhp", model.value().get(0).location());
        Assertions.assertEquals("jumasx", model.value().get(0).tags().get("zj"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.value().get(0).action());
        Assertions.assertEquals("oflokey", model.value().get(0).annotation());
        Assertions.assertEquals("vdcsitynn", 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;
    }
}
