// 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.AzureIaaSvmJobExtendedInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureIaaSvmJobTaskDetails;
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 AzureIaaSvmJobExtendedInfoTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureIaaSvmJobExtendedInfo model =
            BinaryData
                .fromString(
                    "{\"tasksList\":[{\"taskId\":\"epn\",\"startTime\":\"2021-05-29T06:21:05Z\",\"endTime\":\"2021-05-09T12:03:02Z\",\"instanceId\":\"gibbdaxc\",\"duration\":\"PT190H25M17S\",\"status\":\"zauorsuk\",\"progressPercentage\":26.03201613518045,\"taskExecutionDetails\":\"plhlvnuuepzlrp\"}],\"propertyBag\":{\"nnrwrbiork\":\"soldweyuqdunv\",\"xmsivfomiloxggdu\":\"alywjhhgdn\"},\"internalPropertyBag\":{\"hvcyyysfg\":\"ndieuzaofj\"},\"progressPercentage\":99.77033821162951,\"estimatedRemainingDuration\":\"biipuip\",\"dynamicErrorMessage\":\"qonmacj\"}")
                .toObject(AzureIaaSvmJobExtendedInfo.class);
        Assertions.assertEquals("epn", model.tasksList().get(0).taskId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-29T06:21:05Z"), model.tasksList().get(0).startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-09T12:03:02Z"), model.tasksList().get(0).endTime());
        Assertions.assertEquals("gibbdaxc", model.tasksList().get(0).instanceId());
        Assertions.assertEquals(Duration.parse("PT190H25M17S"), model.tasksList().get(0).duration());
        Assertions.assertEquals("zauorsuk", model.tasksList().get(0).status());
        Assertions.assertEquals(26.03201613518045D, model.tasksList().get(0).progressPercentage());
        Assertions.assertEquals("plhlvnuuepzlrp", model.tasksList().get(0).taskExecutionDetails());
        Assertions.assertEquals("soldweyuqdunv", model.propertyBag().get("nnrwrbiork"));
        Assertions.assertEquals("ndieuzaofj", model.internalPropertyBag().get("hvcyyysfg"));
        Assertions.assertEquals(99.77033821162951D, model.progressPercentage());
        Assertions.assertEquals("biipuip", model.estimatedRemainingDuration());
        Assertions.assertEquals("qonmacj", model.dynamicErrorMessage());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureIaaSvmJobExtendedInfo model =
            new AzureIaaSvmJobExtendedInfo()
                .withTasksList(
                    Arrays
                        .asList(
                            new AzureIaaSvmJobTaskDetails()
                                .withTaskId("epn")
                                .withStartTime(OffsetDateTime.parse("2021-05-29T06:21:05Z"))
                                .withEndTime(OffsetDateTime.parse("2021-05-09T12:03:02Z"))
                                .withInstanceId("gibbdaxc")
                                .withDuration(Duration.parse("PT190H25M17S"))
                                .withStatus("zauorsuk")
                                .withProgressPercentage(26.03201613518045D)
                                .withTaskExecutionDetails("plhlvnuuepzlrp")))
                .withPropertyBag(mapOf("nnrwrbiork", "soldweyuqdunv", "xmsivfomiloxggdu", "alywjhhgdn"))
                .withInternalPropertyBag(mapOf("hvcyyysfg", "ndieuzaofj"))
                .withProgressPercentage(99.77033821162951D)
                .withEstimatedRemainingDuration("biipuip")
                .withDynamicErrorMessage("qonmacj");
        model = BinaryData.fromObject(model).toObject(AzureIaaSvmJobExtendedInfo.class);
        Assertions.assertEquals("epn", model.tasksList().get(0).taskId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-29T06:21:05Z"), model.tasksList().get(0).startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-09T12:03:02Z"), model.tasksList().get(0).endTime());
        Assertions.assertEquals("gibbdaxc", model.tasksList().get(0).instanceId());
        Assertions.assertEquals(Duration.parse("PT190H25M17S"), model.tasksList().get(0).duration());
        Assertions.assertEquals("zauorsuk", model.tasksList().get(0).status());
        Assertions.assertEquals(26.03201613518045D, model.tasksList().get(0).progressPercentage());
        Assertions.assertEquals("plhlvnuuepzlrp", model.tasksList().get(0).taskExecutionDetails());
        Assertions.assertEquals("soldweyuqdunv", model.propertyBag().get("nnrwrbiork"));
        Assertions.assertEquals("ndieuzaofj", model.internalPropertyBag().get("hvcyyysfg"));
        Assertions.assertEquals(99.77033821162951D, model.progressPercentage());
        Assertions.assertEquals("biipuip", model.estimatedRemainingDuration());
        Assertions.assertEquals("qonmacj", 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;
    }
}
