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

public final class IpPrefixInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IpPrefixInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"configurationState\":\"ErrorProvisioning\",\"provisioningState\":\"Updating\",\"administrativeState\":\"MAT\",\"ipPrefixRules\":[{\"action\":\"Deny\",\"sequenceNumber\":583976656188902941,\"networkPrefix\":\"jceagb\",\"condition\":\"EqualTo\",\"subnetMaskLength\":\"sumywzashxgonoyj\"}],\"annotation\":\"ipubyznclkfk\"},\"location\":\"bgvopemt\",\"tags\":{\"vn\":\"ujlyegq\",\"lxdbfvabmvms\":\"gflqqbtnyjp\",\"uhvajmailfemjjza\":\"baevwjcnkottl\"},\"id\":\"zwjiqullq\",\"name\":\"bdmvrscmqerndbr\",\"type\":\"yeofltfnnxrkad\"}")
                .toObject(IpPrefixInner.class);
        Assertions.assertEquals("bgvopemt", model.location());
        Assertions.assertEquals("ujlyegq", model.tags().get("vn"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.ipPrefixRules().get(0).action());
        Assertions.assertEquals(583976656188902941L, model.ipPrefixRules().get(0).sequenceNumber());
        Assertions.assertEquals("jceagb", model.ipPrefixRules().get(0).networkPrefix());
        Assertions.assertEquals(Condition.EQUAL_TO, model.ipPrefixRules().get(0).condition());
        Assertions.assertEquals("sumywzashxgonoyj", model.ipPrefixRules().get(0).subnetMaskLength());
        Assertions.assertEquals("ipubyznclkfk", model.annotation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IpPrefixInner model =
            new IpPrefixInner()
                .withLocation("bgvopemt")
                .withTags(mapOf("vn", "ujlyegq", "lxdbfvabmvms", "gflqqbtnyjp", "uhvajmailfemjjza", "baevwjcnkottl"))
                .withIpPrefixRules(
                    Arrays
                        .asList(
                            new IpPrefixRule()
                                .withAction(CommunityActionTypes.DENY)
                                .withSequenceNumber(583976656188902941L)
                                .withNetworkPrefix("jceagb")
                                .withCondition(Condition.EQUAL_TO)
                                .withSubnetMaskLength("sumywzashxgonoyj")))
                .withAnnotation("ipubyznclkfk");
        model = BinaryData.fromObject(model).toObject(IpPrefixInner.class);
        Assertions.assertEquals("bgvopemt", model.location());
        Assertions.assertEquals("ujlyegq", model.tags().get("vn"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.ipPrefixRules().get(0).action());
        Assertions.assertEquals(583976656188902941L, model.ipPrefixRules().get(0).sequenceNumber());
        Assertions.assertEquals("jceagb", model.ipPrefixRules().get(0).networkPrefix());
        Assertions.assertEquals(Condition.EQUAL_TO, model.ipPrefixRules().get(0).condition());
        Assertions.assertEquals("sumywzashxgonoyj", model.ipPrefixRules().get(0).subnetMaskLength());
        Assertions.assertEquals("ipubyznclkfk", 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;
    }
}
