// 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.AccessControlListInner;
import com.azure.resourcemanager.managednetworkfabric.models.AccessControlListConditionProperties;
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 AccessControlListInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AccessControlListInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"addressFamily\":\"ipv6\",\"conditions\":[{\"sequenceNumber\":304908421,\"action\":\"deny\",\"destinationAddress\":\"uv\",\"destinationPort\":\"jxpybczmeh\",\"sourceAddress\":\"tzopbsphrupidgsy\",\"sourcePort\":\"bejhphoycmsxa\",\"protocol\":1376980829,\"annotation\":\"dxbmtqioq\"},{\"sequenceNumber\":1819090851,\"action\":\"allow\",\"destinationAddress\":\"htbmuf\",\"destinationPort\":\"ownoizhw\",\"sourceAddress\":\"rxybqsoq\",\"sourcePort\":\"jgkdmbpazlobcu\",\"protocol\":1769463111,\"annotation\":\"znrb\"},{\"sequenceNumber\":895933338,\"action\":\"allow\",\"destinationAddress\":\"qjnqglhqgnufoooj\",\"destinationPort\":\"wifsq\",\"sourceAddress\":\"saagdf\",\"sourcePort\":\"glzlhjxrifkwmrv\",\"protocol\":1604398792,\"annotation\":\"izntocipao\"}],\"provisioningState\":\"Updating\",\"annotation\":\"s\"},\"location\":\"cmpoyfdkfogkny\",\"tags\":{\"deupewnwrei\":\"fjddeqs\",\"arhmofcqhsmy\":\"jzyflu\"},\"id\":\"rkdtmlxh\",\"name\":\"kuksjtxukcdm\",\"type\":\"arcryuanzwuxzdxt\"}")
                .toObject(AccessControlListInner.class);
        Assertions.assertEquals("cmpoyfdkfogkny", model.location());
        Assertions.assertEquals("fjddeqs", model.tags().get("deupewnwrei"));
        Assertions.assertEquals(AddressFamily.IPV6, model.addressFamily());
        Assertions.assertEquals("dxbmtqioq", model.conditions().get(0).annotation());
        Assertions.assertEquals(304908421, model.conditions().get(0).sequenceNumber());
        Assertions.assertEquals(ConditionActionType.DENY, model.conditions().get(0).action());
        Assertions.assertEquals("uv", model.conditions().get(0).destinationAddress());
        Assertions.assertEquals("jxpybczmeh", model.conditions().get(0).destinationPort());
        Assertions.assertEquals("tzopbsphrupidgsy", model.conditions().get(0).sourceAddress());
        Assertions.assertEquals("bejhphoycmsxa", model.conditions().get(0).sourcePort());
        Assertions.assertEquals(1376980829, model.conditions().get(0).protocol());
        Assertions.assertEquals("s", model.annotation());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AccessControlListInner model =
            new AccessControlListInner()
                .withLocation("cmpoyfdkfogkny")
                .withTags(mapOf("deupewnwrei", "fjddeqs", "arhmofcqhsmy", "jzyflu"))
                .withAddressFamily(AddressFamily.IPV6)
                .withConditions(
                    Arrays
                        .asList(
                            new AccessControlListConditionProperties()
                                .withAnnotation("dxbmtqioq")
                                .withSequenceNumber(304908421)
                                .withAction(ConditionActionType.DENY)
                                .withDestinationAddress("uv")
                                .withDestinationPort("jxpybczmeh")
                                .withSourceAddress("tzopbsphrupidgsy")
                                .withSourcePort("bejhphoycmsxa")
                                .withProtocol(1376980829),
                            new AccessControlListConditionProperties()
                                .withAnnotation("znrb")
                                .withSequenceNumber(1819090851)
                                .withAction(ConditionActionType.ALLOW)
                                .withDestinationAddress("htbmuf")
                                .withDestinationPort("ownoizhw")
                                .withSourceAddress("rxybqsoq")
                                .withSourcePort("jgkdmbpazlobcu")
                                .withProtocol(1769463111),
                            new AccessControlListConditionProperties()
                                .withAnnotation("izntocipao")
                                .withSequenceNumber(895933338)
                                .withAction(ConditionActionType.ALLOW)
                                .withDestinationAddress("qjnqglhqgnufoooj")
                                .withDestinationPort("wifsq")
                                .withSourceAddress("saagdf")
                                .withSourcePort("glzlhjxrifkwmrv")
                                .withProtocol(1604398792)))
                .withAnnotation("s");
        model = BinaryData.fromObject(model).toObject(AccessControlListInner.class);
        Assertions.assertEquals("cmpoyfdkfogkny", model.location());
        Assertions.assertEquals("fjddeqs", model.tags().get("deupewnwrei"));
        Assertions.assertEquals(AddressFamily.IPV6, model.addressFamily());
        Assertions.assertEquals("dxbmtqioq", model.conditions().get(0).annotation());
        Assertions.assertEquals(304908421, model.conditions().get(0).sequenceNumber());
        Assertions.assertEquals(ConditionActionType.DENY, model.conditions().get(0).action());
        Assertions.assertEquals("uv", model.conditions().get(0).destinationAddress());
        Assertions.assertEquals("jxpybczmeh", model.conditions().get(0).destinationPort());
        Assertions.assertEquals("tzopbsphrupidgsy", model.conditions().get(0).sourceAddress());
        Assertions.assertEquals("bejhphoycmsxa", model.conditions().get(0).sourcePort());
        Assertions.assertEquals(1376980829, model.conditions().get(0).protocol());
        Assertions.assertEquals("s", 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;
    }
}
