// 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.AccessControlListConditionProperties;
import com.azure.resourcemanager.managednetworkfabric.models.AccessControlListPatch;
import com.azure.resourcemanager.managednetworkfabric.models.AddressFamily;
import com.azure.resourcemanager.managednetworkfabric.models.ConditionActionType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AccessControlListPatchTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AccessControlListPatch model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"addressFamily\":\"ipv6\",\"conditions\":[{\"sequenceNumber\":300178324,\"action\":\"deny\",\"destinationAddress\":\"nhsjcnyej\",\"destinationPort\":\"kryhtnapczwlokj\",\"sourceAddress\":\"emkkvnipjox\",\"sourcePort\":\"jnchgej\",\"protocol\":1948326965,\"annotation\":\"dmailzydehojw\"},{\"sequenceNumber\":2010120941,\"action\":\"deny\",\"destinationAddress\":\"uxinpmqnjaq\",\"destinationPort\":\"ixjsprozvcputeg\",\"sourceAddress\":\"vwmf\",\"sourcePort\":\"atscmd\",\"protocol\":883957794,\"annotation\":\"hulsuuvmkjozkrwf\"}],\"annotation\":\"iodjp\"},\"tags\":{\"pvwryoqpsoacc\":\"ej\"}}")
                .toObject(AccessControlListPatch.class);
        Assertions.assertEquals("ej", model.tags().get("pvwryoqpsoacc"));
        Assertions.assertEquals(AddressFamily.IPV6, model.addressFamily());
        Assertions.assertEquals("dmailzydehojw", model.conditions().get(0).annotation());
        Assertions.assertEquals(300178324, model.conditions().get(0).sequenceNumber());
        Assertions.assertEquals(ConditionActionType.DENY, model.conditions().get(0).action());
        Assertions.assertEquals("nhsjcnyej", model.conditions().get(0).destinationAddress());
        Assertions.assertEquals("kryhtnapczwlokj", model.conditions().get(0).destinationPort());
        Assertions.assertEquals("emkkvnipjox", model.conditions().get(0).sourceAddress());
        Assertions.assertEquals("jnchgej", model.conditions().get(0).sourcePort());
        Assertions.assertEquals(1948326965, model.conditions().get(0).protocol());
        Assertions.assertEquals("iodjp", model.annotation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AccessControlListPatch model =
            new AccessControlListPatch()
                .withTags(mapOf("pvwryoqpsoacc", "ej"))
                .withAddressFamily(AddressFamily.IPV6)
                .withConditions(
                    Arrays
                        .asList(
                            new AccessControlListConditionProperties()
                                .withAnnotation("dmailzydehojw")
                                .withSequenceNumber(300178324)
                                .withAction(ConditionActionType.DENY)
                                .withDestinationAddress("nhsjcnyej")
                                .withDestinationPort("kryhtnapczwlokj")
                                .withSourceAddress("emkkvnipjox")
                                .withSourcePort("jnchgej")
                                .withProtocol(1948326965),
                            new AccessControlListConditionProperties()
                                .withAnnotation("hulsuuvmkjozkrwf")
                                .withSequenceNumber(2010120941)
                                .withAction(ConditionActionType.DENY)
                                .withDestinationAddress("uxinpmqnjaq")
                                .withDestinationPort("ixjsprozvcputeg")
                                .withSourceAddress("vwmf")
                                .withSourcePort("atscmd")
                                .withProtocol(883957794)))
                .withAnnotation("iodjp");
        model = BinaryData.fromObject(model).toObject(AccessControlListPatch.class);
        Assertions.assertEquals("ej", model.tags().get("pvwryoqpsoacc"));
        Assertions.assertEquals(AddressFamily.IPV6, model.addressFamily());
        Assertions.assertEquals("dmailzydehojw", model.conditions().get(0).annotation());
        Assertions.assertEquals(300178324, model.conditions().get(0).sequenceNumber());
        Assertions.assertEquals(ConditionActionType.DENY, model.conditions().get(0).action());
        Assertions.assertEquals("nhsjcnyej", model.conditions().get(0).destinationAddress());
        Assertions.assertEquals("kryhtnapczwlokj", model.conditions().get(0).destinationPort());
        Assertions.assertEquals("emkkvnipjox", model.conditions().get(0).sourceAddress());
        Assertions.assertEquals("jnchgej", model.conditions().get(0).sourcePort());
        Assertions.assertEquals(1948326965, model.conditions().get(0).protocol());
        Assertions.assertEquals("iodjp", 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;
    }
}
