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

package com.azure.resourcemanager.mediaservices.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.mediaservices.fluent.models.JobInner;
import com.azure.resourcemanager.mediaservices.models.JobInput;
import com.azure.resourcemanager.mediaservices.models.JobOutput;
import com.azure.resourcemanager.mediaservices.models.Priority;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class JobInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JobInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"created\":\"2021-10-13T16:56:21Z\",\"state\":\"Error\",\"description\":\"ixhnrztf\",\"input\":{\"@odata.type\":\"JobInput\"},\"lastModified\":\"2021-01-11T05:27:37Z\",\"outputs\":[{\"@odata.type\":\"JobOutput\",\"state\":\"Processing\",\"progress\":1615716441,\"label\":\"ulppggdtpnapnyir\",\"startTime\":\"2021-02-09T03:01:47Z\",\"endTime\":\"2021-02-20T09:26:33Z\"},{\"@odata.type\":\"JobOutput\",\"state\":\"Processing\",\"progress\":2000011197,\"label\":\"gqgitxmedjvcsl\",\"startTime\":\"2021-02-07T09:50:45Z\",\"endTime\":\"2021-07-27T06:18:52Z\"},{\"@odata.type\":\"JobOutput\",\"state\":\"Canceled\",\"progress\":538641166,\"label\":\"gktrmgucnapkte\",\"startTime\":\"2021-08-31T01:54:16Z\",\"endTime\":\"2021-11-12T01:15:19Z\"},{\"@odata.type\":\"JobOutput\",\"state\":\"Error\",\"progress\":183045537,\"label\":\"fqbuaceopzf\",\"startTime\":\"2021-10-11T15:02:03Z\",\"endTime\":\"2021-03-29T02:40:43Z\"}],\"priority\":\"Low\",\"correlationData\":{\"lzdahzxctobgbkdm\":\"pcqeqx\",\"grcfb\":\"izpost\",\"bpvjymjhx\":\"nrmfqjhhk\"},\"startTime\":\"2021-12-01T23:11:57Z\",\"endTime\":\"2021-11-25T10:52:17Z\"},\"id\":\"divkrt\",\"name\":\"wbxqzvszjfau\",\"type\":\"j\"}")
                .toObject(JobInner.class);
        Assertions.assertEquals("ixhnrztf", model.description());
        Assertions.assertEquals("ulppggdtpnapnyir", model.outputs().get(0).label());
        Assertions.assertEquals(Priority.LOW, model.priority());
        Assertions.assertEquals("pcqeqx", model.correlationData().get("lzdahzxctobgbkdm"));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JobInner model =
            new JobInner()
                .withDescription("ixhnrztf")
                .withInput(new JobInput())
                .withOutputs(
                    Arrays
                        .asList(
                            new JobOutput().withLabel("ulppggdtpnapnyir"),
                            new JobOutput().withLabel("gqgitxmedjvcsl"),
                            new JobOutput().withLabel("gktrmgucnapkte"),
                            new JobOutput().withLabel("fqbuaceopzf")))
                .withPriority(Priority.LOW)
                .withCorrelationData(mapOf("lzdahzxctobgbkdm", "pcqeqx", "grcfb", "izpost", "bpvjymjhx", "nrmfqjhhk"));
        model = BinaryData.fromObject(model).toObject(JobInner.class);
        Assertions.assertEquals("ixhnrztf", model.description());
        Assertions.assertEquals("ulppggdtpnapnyir", model.outputs().get(0).label());
        Assertions.assertEquals(Priority.LOW, model.priority());
        Assertions.assertEquals("pcqeqx", model.correlationData().get("lzdahzxctobgbkdm"));
    }

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