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

package com.azure.resourcemanager.avs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.avs.fluent.models.ScriptExecutionInner;
import com.azure.resourcemanager.avs.models.ScriptExecutionParameter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ScriptExecutionInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ScriptExecutionInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"scriptCmdletId\":\"fxusemdwzr\",\"parameters\":[{\"type\":\"ScriptExecutionParameter\",\"name\":\"apfcqdpsq\"},{\"type\":\"ScriptExecutionParameter\",\"name\":\"qvpsvuoymg\"},{\"type\":\"ScriptExecutionParameter\",\"name\":\"celve\"}],\"hiddenParameters\":[{\"type\":\"ScriptExecutionParameter\",\"name\":\"pqlmfe\"}],\"failureReason\":\"erqwkyhkobopg\",\"timeout\":\"edkowepbqpcrfk\",\"retention\":\"ccsnjvcdwxlpq\",\"submittedAt\":\"2021-11-01T06:00:04Z\",\"startedAt\":\"2021-04-24T05:25:21Z\",\"finishedAt\":\"2021-09-05T20:48:04Z\",\"provisioningState\":\"Cancelled\",\"output\":[\"i\"],\"namedOutputs\":{\"tmtdhtmdvypgik\":\"datafq\",\"irryuzhlh\":\"datagszywk\"},\"information\":[\"qrvqq\",\"atjinrvgoupmfiib\",\"ggjioolvr\"],\"warnings\":[\"v\",\"kkgll\"],\"errors\":[\"ygvjayvblmh\",\"k\",\"uhbxvvy\"]},\"id\":\"gsopbyrqufegxu\",\"name\":\"wz\",\"type\":\"bnhlmc\"}")
                .toObject(ScriptExecutionInner.class);
        Assertions.assertEquals("fxusemdwzr", model.scriptCmdletId());
        Assertions.assertEquals("apfcqdpsq", model.parameters().get(0).name());
        Assertions.assertEquals("pqlmfe", model.hiddenParameters().get(0).name());
        Assertions.assertEquals("erqwkyhkobopg", model.failureReason());
        Assertions.assertEquals("edkowepbqpcrfk", model.timeout());
        Assertions.assertEquals("ccsnjvcdwxlpq", model.retention());
        Assertions.assertEquals("i", model.output().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ScriptExecutionInner model =
            new ScriptExecutionInner()
                .withScriptCmdletId("fxusemdwzr")
                .withParameters(
                    Arrays
                        .asList(
                            new ScriptExecutionParameter().withName("apfcqdpsq"),
                            new ScriptExecutionParameter().withName("qvpsvuoymg"),
                            new ScriptExecutionParameter().withName("celve")))
                .withHiddenParameters(Arrays.asList(new ScriptExecutionParameter().withName("pqlmfe")))
                .withFailureReason("erqwkyhkobopg")
                .withTimeout("edkowepbqpcrfk")
                .withRetention("ccsnjvcdwxlpq")
                .withOutput(Arrays.asList("i"))
                .withNamedOutputs(mapOf("tmtdhtmdvypgik", "datafq", "irryuzhlh", "datagszywk"));
        model = BinaryData.fromObject(model).toObject(ScriptExecutionInner.class);
        Assertions.assertEquals("fxusemdwzr", model.scriptCmdletId());
        Assertions.assertEquals("apfcqdpsq", model.parameters().get(0).name());
        Assertions.assertEquals("pqlmfe", model.hiddenParameters().get(0).name());
        Assertions.assertEquals("erqwkyhkobopg", model.failureReason());
        Assertions.assertEquals("edkowepbqpcrfk", model.timeout());
        Assertions.assertEquals("ccsnjvcdwxlpq", model.retention());
        Assertions.assertEquals("i", model.output().get(0));
    }

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