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

package com.azure.resourcemanager.recoveryservicesbackup.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.recoveryservicesbackup.models.DpmJobExtendedInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.DpmJobTaskDetails;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class DpmJobExtendedInfoTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DpmJobExtendedInfo model =
            BinaryData
                .fromString(
                    "{\"tasksList\":[{\"taskId\":\"mxyasflvgsgzw\",\"startTime\":\"2021-07-22T12:31:34Z\",\"endTime\":\"2021-10-21T09:55:08Z\",\"duration\":\"PT63H9M26S\",\"status\":\"nsmjbl\"},{\"taskId\":\"jhlnymzotqyryu\",\"startTime\":\"2021-05-02T20:27:28Z\",\"endTime\":\"2021-03-01T02:30:44Z\",\"duration\":\"PT89H30M\",\"status\":\"mv\"},{\"taskId\":\"gtayxonsupeujlz\",\"startTime\":\"2020-12-21T20:54:17Z\",\"endTime\":\"2021-04-21T22:02:58Z\",\"duration\":\"PT91H25M34S\",\"status\":\"tnzoibgsxgnxfy\"}],\"propertyBag\":{\"o\":\"mpqoxw\",\"iiqbi\":\"dbxiqx\",\"hfqpofv\":\"htmwwinh\"},\"dynamicErrorMessage\":\"cblembnkbwv\"}")
                .toObject(DpmJobExtendedInfo.class);
        Assertions.assertEquals("mxyasflvgsgzw", model.tasksList().get(0).taskId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-22T12:31:34Z"), model.tasksList().get(0).startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-21T09:55:08Z"), model.tasksList().get(0).endTime());
        Assertions.assertEquals(Duration.parse("PT63H9M26S"), model.tasksList().get(0).duration());
        Assertions.assertEquals("nsmjbl", model.tasksList().get(0).status());
        Assertions.assertEquals("mpqoxw", model.propertyBag().get("o"));
        Assertions.assertEquals("cblembnkbwv", model.dynamicErrorMessage());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DpmJobExtendedInfo model =
            new DpmJobExtendedInfo()
                .withTasksList(
                    Arrays
                        .asList(
                            new DpmJobTaskDetails()
                                .withTaskId("mxyasflvgsgzw")
                                .withStartTime(OffsetDateTime.parse("2021-07-22T12:31:34Z"))
                                .withEndTime(OffsetDateTime.parse("2021-10-21T09:55:08Z"))
                                .withDuration(Duration.parse("PT63H9M26S"))
                                .withStatus("nsmjbl"),
                            new DpmJobTaskDetails()
                                .withTaskId("jhlnymzotqyryu")
                                .withStartTime(OffsetDateTime.parse("2021-05-02T20:27:28Z"))
                                .withEndTime(OffsetDateTime.parse("2021-03-01T02:30:44Z"))
                                .withDuration(Duration.parse("PT89H30M"))
                                .withStatus("mv"),
                            new DpmJobTaskDetails()
                                .withTaskId("gtayxonsupeujlz")
                                .withStartTime(OffsetDateTime.parse("2020-12-21T20:54:17Z"))
                                .withEndTime(OffsetDateTime.parse("2021-04-21T22:02:58Z"))
                                .withDuration(Duration.parse("PT91H25M34S"))
                                .withStatus("tnzoibgsxgnxfy")))
                .withPropertyBag(mapOf("o", "mpqoxw", "iiqbi", "dbxiqx", "hfqpofv", "htmwwinh"))
                .withDynamicErrorMessage("cblembnkbwv");
        model = BinaryData.fromObject(model).toObject(DpmJobExtendedInfo.class);
        Assertions.assertEquals("mxyasflvgsgzw", model.tasksList().get(0).taskId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-22T12:31:34Z"), model.tasksList().get(0).startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-21T09:55:08Z"), model.tasksList().get(0).endTime());
        Assertions.assertEquals(Duration.parse("PT63H9M26S"), model.tasksList().get(0).duration());
        Assertions.assertEquals("nsmjbl", model.tasksList().get(0).status());
        Assertions.assertEquals("mpqoxw", model.propertyBag().get("o"));
        Assertions.assertEquals("cblembnkbwv", model.dynamicErrorMessage());
    }

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