// 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.JobCollection;
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 JobCollectionTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JobCollection model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"created\":\"2021-03-19T00:27:21Z\",\"state\":\"Scheduled\",\"description\":\"srknftguv\",\"lastModified\":\"2021-11-24T12:31:24Z\",\"outputs\":[],\"priority\":\"High\",\"correlationData\":{},\"startTime\":\"2021-06-11T11:55:02Z\",\"endTime\":\"2021-05-29T19:52:45Z\"},\"id\":\"xqtayriwwro\",\"name\":\"qbex\",\"type\":\"mcqibycnojv\"},{\"properties\":{\"created\":\"2021-02-06T03:19:14Z\",\"state\":\"Processing\",\"description\":\"gzva\",\"lastModified\":\"2021-09-24T18:39:34Z\",\"outputs\":[],\"priority\":\"Low\",\"correlationData\":{},\"startTime\":\"2021-09-29T06:33:19Z\",\"endTime\":\"2021-04-21T18:37:49Z\"},\"id\":\"zcjrvxdjzlmwlx\",\"name\":\"vu\",\"type\":\"fhzovawjvzunluth\"},{\"properties\":{\"created\":\"2021-12-09T15:55:09Z\",\"state\":\"Queued\",\"description\":\"peilpjzuaejxdu\",\"lastModified\":\"2021-04-04T06:42:49Z\",\"outputs\":[],\"priority\":\"High\",\"correlationData\":{},\"startTime\":\"2021-04-25T18:40:13Z\",\"endTime\":\"2021-08-12T02:58:19Z\"},\"id\":\"mv\",\"name\":\"ekg\",\"type\":\"wozuhkf\"},{\"properties\":{\"created\":\"2021-02-19T22:50:40Z\",\"state\":\"Canceling\",\"description\":\"dxluu\",\"lastModified\":\"2021-01-22T23:23:23Z\",\"outputs\":[],\"priority\":\"Low\",\"correlationData\":{},\"startTime\":\"2021-10-19T19:08:50Z\",\"endTime\":\"2021-02-11T03:20:25Z\"},\"id\":\"kqvkelnsmvbxwyjs\",\"name\":\"lh\",\"type\":\"caalnjixisxyaw\"}],\"@odata.nextLink\":\"yaqcslyjpkiidz\"}")
                .toObject(JobCollection.class);
        Assertions.assertEquals("srknftguv", model.value().get(0).description());
        Assertions.assertEquals(Priority.HIGH, model.value().get(0).priority());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JobCollection model =
            new JobCollection()
                .withValue(
                    Arrays
                        .asList(
                            new JobInner()
                                .withDescription("srknftguv")
                                .withOutputs(Arrays.asList())
                                .withPriority(Priority.HIGH)
                                .withCorrelationData(mapOf()),
                            new JobInner()
                                .withDescription("gzva")
                                .withOutputs(Arrays.asList())
                                .withPriority(Priority.LOW)
                                .withCorrelationData(mapOf()),
                            new JobInner()
                                .withDescription("peilpjzuaejxdu")
                                .withOutputs(Arrays.asList())
                                .withPriority(Priority.HIGH)
                                .withCorrelationData(mapOf()),
                            new JobInner()
                                .withDescription("dxluu")
                                .withOutputs(Arrays.asList())
                                .withPriority(Priority.LOW)
                                .withCorrelationData(mapOf())));
        model = BinaryData.fromObject(model).toObject(JobCollection.class);
        Assertions.assertEquals("srknftguv", model.value().get(0).description());
        Assertions.assertEquals(Priority.HIGH, model.value().get(0).priority());
    }

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