// 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 java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class IpExtendedCommunityInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IpExtendedCommunityInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"action\":\"Permit\",\"routeTargets\":[\"zrvqdr\",\"bhj\"],\"provisioningState\":\"Failed\",\"annotation\":\"ehoqfbowskan\"},\"location\":\"tzlcuiywgqywgn\",\"tags\":{\"pphrcgynco\":\"ynhz\",\"vmmcoofs\":\"pec\",\"y\":\"lzevgbmqjqab\"},\"id\":\"mivkwlzuvcc\",\"name\":\"wnfnbacf\",\"type\":\"onlebxetqgtzxdpn\"}")
                .toObject(IpExtendedCommunityInner.class);
        Assertions.assertEquals("tzlcuiywgqywgn", model.location());
        Assertions.assertEquals("ynhz", model.tags().get("pphrcgynco"));
        Assertions.assertEquals(CommunityActionTypes.PERMIT, model.action());
        Assertions.assertEquals("zrvqdr", model.routeTargets().get(0));
        Assertions.assertEquals("ehoqfbowskan", model.annotation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IpExtendedCommunityInner model =
            new IpExtendedCommunityInner()
                .withLocation("tzlcuiywgqywgn")
                .withTags(mapOf("pphrcgynco", "ynhz", "vmmcoofs", "pec", "y", "lzevgbmqjqab"))
                .withAction(CommunityActionTypes.PERMIT)
                .withRouteTargets(Arrays.asList("zrvqdr", "bhj"))
                .withAnnotation("ehoqfbowskan");
        model = BinaryData.fromObject(model).toObject(IpExtendedCommunityInner.class);
        Assertions.assertEquals("tzlcuiywgqywgn", model.location());
        Assertions.assertEquals("ynhz", model.tags().get("pphrcgynco"));
        Assertions.assertEquals(CommunityActionTypes.PERMIT, model.action());
        Assertions.assertEquals("zrvqdr", model.routeTargets().get(0));
        Assertions.assertEquals("ehoqfbowskan", model.annotation());
    }

    @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;
    }
}
