// 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.IpPrefixPropertiesIpPrefixRulesItem;
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\":{\"ipPrefixRules\":[{\"action\":\"Deny\",\"sequenceNumber\":2423895035915397618,\"networkPrefix\":\"ctehfiqscjey\",\"condition\":\"EqualTo\",\"subnetMaskLength\":1363658384},{\"action\":\"Deny\",\"sequenceNumber\":3874337962960415689,\"networkPrefix\":\"q\",\"condition\":\"EqualTo\",\"subnetMaskLength\":1874212634}],\"provisioningState\":\"Deleting\",\"annotation\":\"gm\"},\"location\":\"sle\",\"tags\":{\"k\":\"xyqj\",\"jh\":\"attpngjcrcczsq\",\"ysou\":\"mdajv\",\"canoaeupf\":\"q\"},\"id\":\"yhltrpmopjmcm\",\"name\":\"tuo\",\"type\":\"thfuiuaodsfcpkvx\"}")
                .toObject(IpPrefixInner.class);
        Assertions.assertEquals("sle", model.location());
        Assertions.assertEquals("xyqj", model.tags().get("k"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.ipPrefixRules().get(0).action());
        Assertions.assertEquals(2423895035915397618L, model.ipPrefixRules().get(0).sequenceNumber());
        Assertions.assertEquals("ctehfiqscjey", model.ipPrefixRules().get(0).networkPrefix());
        Assertions.assertEquals(Condition.EQUAL_TO, model.ipPrefixRules().get(0).condition());
        Assertions.assertEquals(1363658384, model.ipPrefixRules().get(0).subnetMaskLength());
        Assertions.assertEquals("gm", model.annotation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        IpPrefixInner model =
            new IpPrefixInner()
                .withLocation("sle")
                .withTags(mapOf("k", "xyqj", "jh", "attpngjcrcczsq", "ysou", "mdajv", "canoaeupf", "q"))
                .withIpPrefixRules(
                    Arrays
                        .asList(
                            new IpPrefixPropertiesIpPrefixRulesItem()
                                .withAction(CommunityActionTypes.DENY)
                                .withSequenceNumber(2423895035915397618L)
                                .withNetworkPrefix("ctehfiqscjey")
                                .withCondition(Condition.EQUAL_TO)
                                .withSubnetMaskLength(1363658384),
                            new IpPrefixPropertiesIpPrefixRulesItem()
                                .withAction(CommunityActionTypes.DENY)
                                .withSequenceNumber(3874337962960415689L)
                                .withNetworkPrefix("q")
                                .withCondition(Condition.EQUAL_TO)
                                .withSubnetMaskLength(1874212634)))
                .withAnnotation("gm");
        model = BinaryData.fromObject(model).toObject(IpPrefixInner.class);
        Assertions.assertEquals("sle", model.location());
        Assertions.assertEquals("xyqj", model.tags().get("k"));
        Assertions.assertEquals(CommunityActionTypes.DENY, model.ipPrefixRules().get(0).action());
        Assertions.assertEquals(2423895035915397618L, model.ipPrefixRules().get(0).sequenceNumber());
        Assertions.assertEquals("ctehfiqscjey", model.ipPrefixRules().get(0).networkPrefix());
        Assertions.assertEquals(Condition.EQUAL_TO, model.ipPrefixRules().get(0).condition());
        Assertions.assertEquals(1363658384, model.ipPrefixRules().get(0).subnetMaskLength());
        Assertions.assertEquals("gm", 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;
    }
}
