// 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.WorkflowProperties;
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 WorkflowPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WorkflowProperties model =
            BinaryData
                .fromString(
                    "{\"provisioningState\":\"Renewing\",\"createdTime\":\"2021-06-21T13:48:53Z\",\"changedTime\":\"2021-01-30T10:40:21Z\",\"state\":\"Suspended\",\"version\":\"uskcqvkocrcj\",\"accessEndpoint\":\"wtnhxbnjbiksqr\",\"endpointsConfiguration\":{\"workflow\":{\"outgoingIpAddresses\":[],\"accessEndpointIpAddresses\":[]},\"connector\":{\"outgoingIpAddresses\":[],\"accessEndpointIpAddresses\":[]}},\"accessControl\":{\"triggers\":{\"allowedCallerIpAddresses\":[]},\"contents\":{\"allowedCallerIpAddresses\":[]},\"actions\":{\"allowedCallerIpAddresses\":[]},\"workflowManagement\":{\"allowedCallerIpAddresses\":[]}},\"sku\":{\"name\":\"Premium\",\"plan\":{\"id\":\"duuji\",\"name\":\"jczdzevndh\",\"type\":\"wpdappdsbdkv\"}},\"integrationAccount\":{\"id\":\"jfeusnh\",\"name\":\"je\",\"type\":\"mrldhu\"},\"integrationServiceEnvironment\":{\"id\":\"zdatqxhocdg\",\"name\":\"blgphuticn\",\"type\":\"kao\"},\"definition\":\"datayiftyhxhuro\",\"parameters\":{\"koty\":{\"type\":\"SecureString\",\"value\":\"datalniwpwcukjfkgiaw\",\"metadata\":\"datalryplwckbasyy\",\"description\":\"ddhsgcbacphe\"},\"xybz\":{\"type\":\"String\",\"value\":\"dataulzndlikwyqk\",\"metadata\":\"datagibma\",\"description\":\"akeqs\"},\"dmgloug\":{\"type\":\"SecureObject\",\"value\":\"dataqytbciq\",\"metadata\":\"datauflmm\",\"description\":\"zsm\"}}}")
                .toObject(WorkflowProperties.class);
        Assertions.assertEquals(WorkflowState.SUSPENDED, model.state());
        Assertions.assertEquals("jfeusnh", model.integrationAccount().id());
        Assertions.assertEquals("zdatqxhocdg", model.integrationServiceEnvironment().id());
        Assertions.assertEquals(ParameterType.SECURE_STRING, model.parameters().get("koty").type());
        Assertions.assertEquals("ddhsgcbacphe", model.parameters().get("koty").description());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WorkflowProperties model =
            new WorkflowProperties()
                .withState(WorkflowState.SUSPENDED)
                .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("jfeusnh"))
                .withIntegrationServiceEnvironment(new ResourceReference().withId("zdatqxhocdg"))
                .withDefinition("datayiftyhxhuro")
                .withParameters(
                    mapOf(
                        "koty",
                        new WorkflowParameter()
                            .withType(ParameterType.SECURE_STRING)
                            .withValue("datalniwpwcukjfkgiaw")
                            .withMetadata("datalryplwckbasyy")
                            .withDescription("ddhsgcbacphe"),
                        "xybz",
                        new WorkflowParameter()
                            .withType(ParameterType.STRING)
                            .withValue("dataulzndlikwyqk")
                            .withMetadata("datagibma")
                            .withDescription("akeqs"),
                        "dmgloug",
                        new WorkflowParameter()
                            .withType(ParameterType.SECURE_OBJECT)
                            .withValue("dataqytbciq")
                            .withMetadata("datauflmm")
                            .withDescription("zsm")));
        model = BinaryData.fromObject(model).toObject(WorkflowProperties.class);
        Assertions.assertEquals(WorkflowState.SUSPENDED, model.state());
        Assertions.assertEquals("jfeusnh", model.integrationAccount().id());
        Assertions.assertEquals("zdatqxhocdg", model.integrationServiceEnvironment().id());
        Assertions.assertEquals(ParameterType.SECURE_STRING, model.parameters().get("koty").type());
        Assertions.assertEquals("ddhsgcbacphe", model.parameters().get("koty").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;
    }
}
