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

public final class WorkflowVersionListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WorkflowVersionListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"provisioningState\":\"Waiting\",\"createdTime\":\"2021-07-19T23:52:41Z\",\"changedTime\":\"2021-09-21T08:29:33Z\",\"state\":\"Completed\",\"version\":\"jease\",\"accessEndpoint\":\"heoflokeyyienjbd\",\"definition\":\"datapdjpjumasxazjp\",\"parameters\":{}},\"location\":\"e\",\"tags\":{\"wdslfhotwmcy\":\"lhbxxhejjzzvdud\",\"cftadeh\":\"pwlbjnpg\"},\"id\":\"nltyfsoppusuesnz\",\"name\":\"dejbavo\",\"type\":\"xzdmohctb\"}],\"nextLink\":\"udwxdndnvowguj\"}")
                .toObject(WorkflowVersionListResult.class);
        Assertions.assertEquals("e", model.value().get(0).location());
        Assertions.assertEquals("lhbxxhejjzzvdud", model.value().get(0).tags().get("wdslfhotwmcy"));
        Assertions.assertEquals(WorkflowState.COMPLETED, model.value().get(0).state());
        Assertions.assertEquals("udwxdndnvowguj", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WorkflowVersionListResult model =
            new WorkflowVersionListResult()
                .withValue(
                    Arrays
                        .asList(
                            new WorkflowVersionInner()
                                .withLocation("e")
                                .withTags(mapOf("wdslfhotwmcy", "lhbxxhejjzzvdud", "cftadeh", "pwlbjnpg"))
                                .withState(WorkflowState.COMPLETED)
                                .withDefinition("datapdjpjumasxazjp")
                                .withParameters(mapOf())))
                .withNextLink("udwxdndnvowguj");
        model = BinaryData.fromObject(model).toObject(WorkflowVersionListResult.class);
        Assertions.assertEquals("e", model.value().get(0).location());
        Assertions.assertEquals("lhbxxhejjzzvdud", model.value().get(0).tags().get("wdslfhotwmcy"));
        Assertions.assertEquals(WorkflowState.COMPLETED, model.value().get(0).state());
        Assertions.assertEquals("udwxdndnvowguj", model.nextLink());
    }

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