// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.logic.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.logic.models.FlowAccessControlConfiguration;
import com.azure.resourcemanager.logic.models.FlowAccessControlConfigurationPolicy;
import com.azure.resourcemanager.logic.models.IpAddressRange;
import com.azure.resourcemanager.logic.models.OpenAuthenticationAccessPolicies;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class FlowAccessControlConfigurationTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        FlowAccessControlConfiguration model =
            BinaryData
                .fromString(
                    "{\"triggers\":{\"allowedCallerIpAddresses\":[{\"addressRange\":\"mijcmmxdcufufs\"},{\"addressRange\":\"ymzidn\"},{\"addressRange\":\"zcxtbzsgfyccsn\"},{\"addressRange\":\"mdwzjeiachboo\"}],\"openAuthenticationPolicies\":{\"policies\":{}}},\"contents\":{\"allowedCallerIpAddresses\":[{\"addressRange\":\"qpteeh\"},{\"addressRange\":\"vypyqrimzinpv\"},{\"addressRange\":\"jdkirsoodqx\"}],\"openAuthenticationPolicies\":{\"policies\":{}}},\"actions\":{\"allowedCallerIpAddresses\":[{\"addressRange\":\"t\"},{\"addressRange\":\"whdsoifiyip\"}],\"openAuthenticationPolicies\":{\"policies\":{}}},\"workflowManagement\":{\"allowedCallerIpAddresses\":[{\"addressRange\":\"jbznorc\"}],\"openAuthenticationPolicies\":{\"policies\":{}}}}")
                .toObject(FlowAccessControlConfiguration.class);
        Assertions.assertEquals("mijcmmxdcufufs", model.triggers().allowedCallerIpAddresses().get(0).addressRange());
        Assertions.assertEquals("qpteeh", model.contents().allowedCallerIpAddresses().get(0).addressRange());
        Assertions.assertEquals("t", model.actions().allowedCallerIpAddresses().get(0).addressRange());
        Assertions.assertEquals("jbznorc", model.workflowManagement().allowedCallerIpAddresses().get(0).addressRange());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        FlowAccessControlConfiguration model =
            new FlowAccessControlConfiguration()
                .withTriggers(
                    new FlowAccessControlConfigurationPolicy()
                        .withAllowedCallerIpAddresses(
                            Arrays
                                .asList(
                                    new IpAddressRange().withAddressRange("mijcmmxdcufufs"),
                                    new IpAddressRange().withAddressRange("ymzidn"),
                                    new IpAddressRange().withAddressRange("zcxtbzsgfyccsn"),
                                    new IpAddressRange().withAddressRange("mdwzjeiachboo")))
                        .withOpenAuthenticationPolicies(new OpenAuthenticationAccessPolicies().withPolicies(mapOf())))
                .withContents(
                    new FlowAccessControlConfigurationPolicy()
                        .withAllowedCallerIpAddresses(
                            Arrays
                                .asList(
                                    new IpAddressRange().withAddressRange("qpteeh"),
                                    new IpAddressRange().withAddressRange("vypyqrimzinpv"),
                                    new IpAddressRange().withAddressRange("jdkirsoodqx")))
                        .withOpenAuthenticationPolicies(new OpenAuthenticationAccessPolicies().withPolicies(mapOf())))
                .withActions(
                    new FlowAccessControlConfigurationPolicy()
                        .withAllowedCallerIpAddresses(
                            Arrays
                                .asList(
                                    new IpAddressRange().withAddressRange("t"),
                                    new IpAddressRange().withAddressRange("whdsoifiyip")))
                        .withOpenAuthenticationPolicies(new OpenAuthenticationAccessPolicies().withPolicies(mapOf())))
                .withWorkflowManagement(
                    new FlowAccessControlConfigurationPolicy()
                        .withAllowedCallerIpAddresses(Arrays.asList(new IpAddressRange().withAddressRange("jbznorc")))
                        .withOpenAuthenticationPolicies(new OpenAuthenticationAccessPolicies().withPolicies(mapOf())));
        model = BinaryData.fromObject(model).toObject(FlowAccessControlConfiguration.class);
        Assertions.assertEquals("mijcmmxdcufufs", model.triggers().allowedCallerIpAddresses().get(0).addressRange());
        Assertions.assertEquals("qpteeh", model.contents().allowedCallerIpAddresses().get(0).addressRange());
        Assertions.assertEquals("t", model.actions().allowedCallerIpAddresses().get(0).addressRange());
        Assertions.assertEquals("jbznorc", model.workflowManagement().allowedCallerIpAddresses().get(0).addressRange());
    }

    @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;
    }
}
