// 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.WorkflowVersionInner;
import com.azure.resourcemanager.logic.models.FlowAccessControlConfiguration;
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.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class WorkflowVersionInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WorkflowVersionInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"Succeeded\",\"createdTime\":\"2021-09-16T14:46:13Z\",\"changedTime\":\"2021-03-07T18:06:24Z\",\"state\":\"Suspended\",\"version\":\"lazjdyggdtjixhbk\",\"accessEndpoint\":\"fqweykhmene\",\"endpointsConfiguration\":{},\"accessControl\":{},\"sku\":{\"name\":\"Free\"},\"integrationAccount\":{\"id\":\"yvdcsitynnaa\",\"name\":\"ectehf\",\"type\":\"scjeypv\"},\"definition\":\"datazrkgqhcjrefovg\",\"parameters\":{\"ounqecano\":{\"type\":\"String\",\"value\":\"datayyvxyqjpkcattpn\",\"metadata\":\"datacr\",\"description\":\"zsqpjhvmdajvny\"}}},\"location\":\"eupfhyhltrpm\",\"tags\":{\"odsfcpkvxodpuozm\":\"mcmatuokthfuiu\",\"ktwh\":\"zydagfuaxbezyiuo\",\"o\":\"dxwzywqsmbsurexi\",\"fksymddystki\":\"yocf\"},\"id\":\"uxh\",\"name\":\"yudxorrqnbp\",\"type\":\"czvyifq\"}")
                .toObject(WorkflowVersionInner.class);
        Assertions.assertEquals("eupfhyhltrpm", model.location());
        Assertions.assertEquals("mcmatuokthfuiu", model.tags().get("odsfcpkvxodpuozm"));
        Assertions.assertEquals(WorkflowState.SUSPENDED, model.state());
        Assertions.assertEquals("yvdcsitynnaa", model.integrationAccount().id());
        Assertions.assertEquals(ParameterType.STRING, model.parameters().get("ounqecano").type());
        Assertions.assertEquals("zsqpjhvmdajvny", model.parameters().get("ounqecano").description());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WorkflowVersionInner model =
            new WorkflowVersionInner()
                .withLocation("eupfhyhltrpm")
                .withTags(
                    mapOf(
                        "odsfcpkvxodpuozm",
                        "mcmatuokthfuiu",
                        "ktwh",
                        "zydagfuaxbezyiuo",
                        "o",
                        "dxwzywqsmbsurexi",
                        "fksymddystki",
                        "yocf"))
                .withState(WorkflowState.SUSPENDED)
                .withEndpointsConfiguration(new FlowEndpointsConfiguration())
                .withAccessControl(new FlowAccessControlConfiguration())
                .withIntegrationAccount(new ResourceReference().withId("yvdcsitynnaa"))
                .withDefinition("datazrkgqhcjrefovg")
                .withParameters(
                    mapOf(
                        "ounqecano",
                        new WorkflowParameter()
                            .withType(ParameterType.STRING)
                            .withValue("datayyvxyqjpkcattpn")
                            .withMetadata("datacr")
                            .withDescription("zsqpjhvmdajvny")));
        model = BinaryData.fromObject(model).toObject(WorkflowVersionInner.class);
        Assertions.assertEquals("eupfhyhltrpm", model.location());
        Assertions.assertEquals("mcmatuokthfuiu", model.tags().get("odsfcpkvxodpuozm"));
        Assertions.assertEquals(WorkflowState.SUSPENDED, model.state());
        Assertions.assertEquals("yvdcsitynnaa", model.integrationAccount().id());
        Assertions.assertEquals(ParameterType.STRING, model.parameters().get("ounqecano").type());
        Assertions.assertEquals("zsqpjhvmdajvny", model.parameters().get("ounqecano").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;
    }
}
