// 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.models.CommunityActionTypes;
import com.azure.resourcemanager.managednetworkfabric.models.Condition;
import com.azure.resourcemanager.managednetworkfabric.models.IpPrefixPatch;
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 IpPrefixPatchTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        IpPrefixPatch model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"ipPrefixRules\":[{\"action\":\"Deny\",\"sequenceNumber\":6160965554069396867,\"networkPrefix\":\"meikj\",\"condition\":\"GreaterThanOrEqualTo\",\"subnetMaskLength\":\"acnmwpfsuqtaaz\"},{\"action\":\"Deny\",\"sequenceNumber\":6514356220844610771,\"networkPrefix\":\"yxoyfp\",\"condition\":\"EqualTo\",\"subnetMaskLength\":\"qezxlhdj\"}],\"annotation\":\"dcadwvpsozjiihjr\"},\"tags\":{\"xwdvwnj\":\"mrzoep\",\"nmx\":\"gv\",\"ibtyibuyvpirfqjp\":\"ursqf\"}}")
                .toObject(IpPrefixPatch.class);
        Assertions.assertEquals("mrzoep", model.tags().get("xwdvwnj"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.ipPrefixRules().get(0).action());
        Assertions.assertEquals(6160965554069396867L, model.ipPrefixRules().get(0).sequenceNumber());
        Assertions.assertEquals("meikj", model.ipPrefixRules().get(0).networkPrefix());
        Assertions.assertEquals(Condition.GREATER_THAN_OR_EQUAL_TO, model.ipPrefixRules().get(0).condition());
        Assertions.assertEquals("acnmwpfsuqtaaz", model.ipPrefixRules().get(0).subnetMaskLength());
        Assertions.assertEquals("dcadwvpsozjiihjr", model.annotation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IpPrefixPatch model =
            new IpPrefixPatch()
                .withTags(mapOf("xwdvwnj", "mrzoep", "nmx", "gv", "ibtyibuyvpirfqjp", "ursqf"))
                .withIpPrefixRules(
                    Arrays
                        .asList(
                            new IpPrefixRule()
                                .withAction(CommunityActionTypes.DENY)
                                .withSequenceNumber(6160965554069396867L)
                                .withNetworkPrefix("meikj")
                                .withCondition(Condition.GREATER_THAN_OR_EQUAL_TO)
                                .withSubnetMaskLength("acnmwpfsuqtaaz"),
                            new IpPrefixRule()
                                .withAction(CommunityActionTypes.DENY)
                                .withSequenceNumber(6514356220844610771L)
                                .withNetworkPrefix("yxoyfp")
                                .withCondition(Condition.EQUAL_TO)
                                .withSubnetMaskLength("qezxlhdj")))
                .withAnnotation("dcadwvpsozjiihjr");
        model = BinaryData.fromObject(model).toObject(IpPrefixPatch.class);
        Assertions.assertEquals("mrzoep", model.tags().get("xwdvwnj"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.ipPrefixRules().get(0).action());
        Assertions.assertEquals(6160965554069396867L, model.ipPrefixRules().get(0).sequenceNumber());
        Assertions.assertEquals("meikj", model.ipPrefixRules().get(0).networkPrefix());
        Assertions.assertEquals(Condition.GREATER_THAN_OR_EQUAL_TO, model.ipPrefixRules().get(0).condition());
        Assertions.assertEquals("acnmwpfsuqtaaz", model.ipPrefixRules().get(0).subnetMaskLength());
        Assertions.assertEquals("dcadwvpsozjiihjr", 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;
    }
}
