// 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.fluent.models.WorkflowVersionProperties;
import com.azure.resourcemanager.logic.models.FlowAccessControlConfiguration;
import com.azure.resourcemanager.logic.models.FlowAccessControlConfigurationPolicy;
import com.azure.resourcemanager.logic.models.FlowEndpoints;
import com.azure.resourcemanager.logic.models.FlowEndpointsConfiguration;
import com.azure.resourcemanager.logic.models.ParameterType;
import com.azure.resourcemanager.logic.models.ResourceReference;
import com.azure.resourcemanager.logic.models.WorkflowParameter;
import com.azure.resourcemanager.logic.models.WorkflowState;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class WorkflowVersionPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WorkflowVersionProperties model =
            BinaryData
                .fromString(
                    "{\"provisioningState\":\"Accepted\",\"createdTime\":\"2021-11-06T12:54:53Z\",\"changedTime\":\"2020-12-20T14:51:17Z\",\"state\":\"Completed\",\"version\":\"mvvd\",\"accessEndpoint\":\"atkpnp\",\"endpointsConfiguration\":{\"workflow\":{\"outgoingIpAddresses\":[],\"accessEndpointIpAddresses\":[]},\"connector\":{\"outgoingIpAddresses\":[],\"accessEndpointIpAddresses\":[]}},\"accessControl\":{\"triggers\":{\"allowedCallerIpAddresses\":[]},\"contents\":{\"allowedCallerIpAddresses\":[]},\"actions\":{\"allowedCallerIpAddresses\":[]},\"workflowManagement\":{\"allowedCallerIpAddresses\":[]}},\"sku\":{\"name\":\"Shared\",\"plan\":{\"id\":\"lhzdobp\",\"name\":\"mflbv\",\"type\":\"chrkcciwwzjuqk\"}},\"integrationAccount\":{\"id\":\"ajiwkuo\",\"name\":\"skghsauuimj\",\"type\":\"xieduugidyjrr\"},\"definition\":\"datay\",\"parameters\":{\"vfaxkffeiith\":{\"type\":\"Int\",\"value\":\"datacsonpclhoco\",\"metadata\":\"datalkevle\",\"description\":\"zfbuhf\"},\"oenkouknvudwti\":{\"type\":\"String\",\"value\":\"datazy\",\"metadata\":\"datahxmzsbbzoggig\",\"description\":\"wburvjxxjnspydpt\"},\"npiucgygevqznty\":{\"type\":\"Array\",\"value\":\"datadng\",\"metadata\":\"dataocipazyxoeg\",\"description\":\"g\"},\"jzicwifsjt\":{\"type\":\"NotSpecified\",\"value\":\"datap\",\"metadata\":\"datac\",\"description\":\"qjsdpydnfyhxdeo\"}}}")
                .toObject(WorkflowVersionProperties.class);
        Assertions.assertEquals(WorkflowState.COMPLETED, model.state());
        Assertions.assertEquals("ajiwkuo", model.integrationAccount().id());
        Assertions.assertEquals(ParameterType.INT, model.parameters().get("vfaxkffeiith").type());
        Assertions.assertEquals("zfbuhf", model.parameters().get("vfaxkffeiith").description());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WorkflowVersionProperties model =
            new WorkflowVersionProperties()
                .withState(WorkflowState.COMPLETED)
                .withEndpointsConfiguration(
                    new FlowEndpointsConfiguration()
                        .withWorkflow(
                            new FlowEndpoints()
                                .withOutgoingIpAddresses(Arrays.asList())
                                .withAccessEndpointIpAddresses(Arrays.asList()))
                        .withConnector(
                            new FlowEndpoints()
                                .withOutgoingIpAddresses(Arrays.asList())
                                .withAccessEndpointIpAddresses(Arrays.asList())))
                .withAccessControl(
                    new FlowAccessControlConfiguration()
                        .withTriggers(
                            new FlowAccessControlConfigurationPolicy().withAllowedCallerIpAddresses(Arrays.asList()))
                        .withContents(
                            new FlowAccessControlConfigurationPolicy().withAllowedCallerIpAddresses(Arrays.asList()))
                        .withActions(
                            new FlowAccessControlConfigurationPolicy().withAllowedCallerIpAddresses(Arrays.asList()))
                        .withWorkflowManagement(
                            new FlowAccessControlConfigurationPolicy().withAllowedCallerIpAddresses(Arrays.asList())))
                .withIntegrationAccount(new ResourceReference().withId("ajiwkuo"))
                .withDefinition("datay")
                .withParameters(
                    mapOf(
                        "vfaxkffeiith",
                        new WorkflowParameter()
                            .withType(ParameterType.INT)
                            .withValue("datacsonpclhoco")
                            .withMetadata("datalkevle")
                            .withDescription("zfbuhf"),
                        "oenkouknvudwti",
                        new WorkflowParameter()
                            .withType(ParameterType.STRING)
                            .withValue("datazy")
                            .withMetadata("datahxmzsbbzoggig")
                            .withDescription("wburvjxxjnspydpt"),
                        "npiucgygevqznty",
                        new WorkflowParameter()
                            .withType(ParameterType.ARRAY)
                            .withValue("datadng")
                            .withMetadata("dataocipazyxoeg")
                            .withDescription("g"),
                        "jzicwifsjt",
                        new WorkflowParameter()
                            .withType(ParameterType.NOT_SPECIFIED)
                            .withValue("datap")
                            .withMetadata("datac")
                            .withDescription("qjsdpydnfyhxdeo")));
        model = BinaryData.fromObject(model).toObject(WorkflowVersionProperties.class);
        Assertions.assertEquals(WorkflowState.COMPLETED, model.state());
        Assertions.assertEquals("ajiwkuo", model.integrationAccount().id());
        Assertions.assertEquals(ParameterType.INT, model.parameters().get("vfaxkffeiith").type());
        Assertions.assertEquals("zfbuhf", model.parameters().get("vfaxkffeiith").description());
    }

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