// 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.ScriptExecutionProperties;
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 ScriptExecutionPropertiesTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ScriptExecutionProperties model =
            BinaryData
                .fromString(
                    "{\"scriptCmdletId\":\"utnwytpzdmovzvf\",\"parameters\":[{\"type\":\"ScriptExecutionParameter\",\"name\":\"wzqa\"},{\"type\":\"ScriptExecutionParameter\",\"name\":\"f\"}],\"hiddenParameters\":[{\"type\":\"ScriptExecutionParameter\",\"name\":\"ur\"}],\"failureReason\":\"laecxndticok\",\"timeout\":\"vzm\",\"retention\":\"t\",\"submittedAt\":\"2021-01-29T20:58:55Z\",\"startedAt\":\"2021-12-03T00:07:08Z\",\"finishedAt\":\"2021-05-21T11:49:52Z\",\"provisioningState\":\"Failed\",\"output\":[\"lnpkciay\",\"riykhyawfvjlbox\"],\"namedOutputs\":{\"digumbnr\":\"datajlmxhomdynhd\",\"hezwwvaiq\":\"dataauzzptjazysd\"},\"information\":[\"vfonkphhqyikvyl\"],\"warnings\":[\"avluwmncs\",\"tijfybvp\",\"ekrsgs\"],\"errors\":[\"huzqgn\",\"dgkynscliqhzvhxn\",\"omtkub\"]}")
                .toObject(ScriptExecutionProperties.class);
        Assertions.assertEquals("utnwytpzdmovzvf", model.scriptCmdletId());
        Assertions.assertEquals("wzqa", model.parameters().get(0).name());
        Assertions.assertEquals("ur", model.hiddenParameters().get(0).name());
        Assertions.assertEquals("laecxndticok", model.failureReason());
        Assertions.assertEquals("vzm", model.timeout());
        Assertions.assertEquals("t", model.retention());
        Assertions.assertEquals("lnpkciay", model.output().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ScriptExecutionProperties model =
            new ScriptExecutionProperties()
                .withScriptCmdletId("utnwytpzdmovzvf")
                .withParameters(
                    Arrays
                        .asList(
                            new ScriptExecutionParameter().withName("wzqa"),
                            new ScriptExecutionParameter().withName("f")))
                .withHiddenParameters(Arrays.asList(new ScriptExecutionParameter().withName("ur")))
                .withFailureReason("laecxndticok")
                .withTimeout("vzm")
                .withRetention("t")
                .withOutput(Arrays.asList("lnpkciay", "riykhyawfvjlbox"))
                .withNamedOutputs(mapOf("digumbnr", "datajlmxhomdynhd", "hezwwvaiq", "dataauzzptjazysd"));
        model = BinaryData.fromObject(model).toObject(ScriptExecutionProperties.class);
        Assertions.assertEquals("utnwytpzdmovzvf", model.scriptCmdletId());
        Assertions.assertEquals("wzqa", model.parameters().get(0).name());
        Assertions.assertEquals("ur", model.hiddenParameters().get(0).name());
        Assertions.assertEquals("laecxndticok", model.failureReason());
        Assertions.assertEquals("vzm", model.timeout());
        Assertions.assertEquals("t", model.retention());
        Assertions.assertEquals("lnpkciay", model.output().get(0));
    }

    // Use "Map.of" if available
    @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;
    }
}
