// 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.BackupManagementType;
import com.azure.resourcemanager.recoveryservicesbackup.models.JobSupportedAction;
import com.azure.resourcemanager.recoveryservicesbackup.models.MabErrorInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.MabJob;
import com.azure.resourcemanager.recoveryservicesbackup.models.MabJobExtendedInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.MabJobTaskDetails;
import com.azure.resourcemanager.recoveryservicesbackup.models.MabServerType;
import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadType;
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 MabJobTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        MabJob model =
            BinaryData
                .fromString(
                    "{\"jobType\":\"MabJob\",\"duration\":\"PT78H42M28S\",\"actionsInfo\":[\"Cancellable\",\"Invalid\",\"Invalid\"],\"mabServerName\":\"ubqmamh\",\"mabServerType\":\"AzureSqlContainer\",\"workloadType\":\"SQLDB\",\"errorDetails\":[{\"errorString\":\"azttaboidvmfq\",\"recommendations\":[\"ubowsepdfgkm\",\"dherngbtcj\",\"ahokqtobkauxofsh\"]}],\"extendedInfo\":{\"tasksList\":[{\"taskId\":\"nulaiywzejywhsl\",\"startTime\":\"2021-06-09T06:05:44Z\",\"endTime\":\"2021-10-11T08:16:03Z\",\"duration\":\"PT94H10M55S\",\"status\":\"npdwr\"},{\"taskId\":\"afgfugsnn\",\"startTime\":\"2021-08-26T04:30:17Z\",\"endTime\":\"2021-07-08T15:54:36Z\",\"duration\":\"PT135H28M58S\",\"status\":\"pococtfjgt\"},{\"taskId\":\"rjvzuyt\",\"startTime\":\"2021-03-14T11:53:49Z\",\"endTime\":\"2021-04-19T09:03:23Z\",\"duration\":\"PT181H51M44S\",\"status\":\"olbauirop\"},{\"taskId\":\"nszonwpngaj\",\"startTime\":\"2020-12-27T04:22:49Z\",\"endTime\":\"2021-06-01T23:38:48Z\",\"duration\":\"PT189H58M33S\",\"status\":\"rtmjfj\"}],\"propertyBag\":{\"nlusfnrd\":\"cxlzhcoxovnekh\",\"tjvidt\":\"jxtxrdc\",\"uwkasiz\":\"gepuslvyjtc\",\"qfecjxeygtuhx\":\"esfuught\"},\"dynamicErrorMessage\":\"cbuewmrswnjlxuz\"},\"entityFriendlyName\":\"wpusxjbaqehg\",\"backupManagementType\":\"MAB\",\"operation\":\"zjqatucoig\",\"status\":\"xncnwfe\",\"startTime\":\"2021-04-30T09:19:55Z\",\"endTime\":\"2021-09-02T11:06:06Z\",\"activityId\":\"m\"}")
                .toObject(MabJob.class);
        Assertions.assertEquals("wpusxjbaqehg", model.entityFriendlyName());
        Assertions.assertEquals(BackupManagementType.MAB, model.backupManagementType());
        Assertions.assertEquals("zjqatucoig", model.operation());
        Assertions.assertEquals("xncnwfe", model.status());
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-30T09:19:55Z"), model.startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-02T11:06:06Z"), model.endTime());
        Assertions.assertEquals("m", model.activityId());
        Assertions.assertEquals(Duration.parse("PT78H42M28S"), model.duration());
        Assertions.assertEquals(JobSupportedAction.CANCELLABLE, model.actionsInfo().get(0));
        Assertions.assertEquals("ubqmamh", model.mabServerName());
        Assertions.assertEquals(MabServerType.AZURE_SQL_CONTAINER, model.mabServerType());
        Assertions.assertEquals(WorkloadType.SQLDB, model.workloadType());
        Assertions.assertEquals("nulaiywzejywhsl", model.extendedInfo().tasksList().get(0).taskId());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-06-09T06:05:44Z"), model.extendedInfo().tasksList().get(0).startTime());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-10-11T08:16:03Z"), model.extendedInfo().tasksList().get(0).endTime());
        Assertions.assertEquals(Duration.parse("PT94H10M55S"), model.extendedInfo().tasksList().get(0).duration());
        Assertions.assertEquals("npdwr", model.extendedInfo().tasksList().get(0).status());
        Assertions.assertEquals("cxlzhcoxovnekh", model.extendedInfo().propertyBag().get("nlusfnrd"));
        Assertions.assertEquals("cbuewmrswnjlxuz", model.extendedInfo().dynamicErrorMessage());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        MabJob model =
            new MabJob()
                .withEntityFriendlyName("wpusxjbaqehg")
                .withBackupManagementType(BackupManagementType.MAB)
                .withOperation("zjqatucoig")
                .withStatus("xncnwfe")
                .withStartTime(OffsetDateTime.parse("2021-04-30T09:19:55Z"))
                .withEndTime(OffsetDateTime.parse("2021-09-02T11:06:06Z"))
                .withActivityId("m")
                .withDuration(Duration.parse("PT78H42M28S"))
                .withActionsInfo(
                    Arrays
                        .asList(JobSupportedAction.CANCELLABLE, JobSupportedAction.INVALID, JobSupportedAction.INVALID))
                .withMabServerName("ubqmamh")
                .withMabServerType(MabServerType.AZURE_SQL_CONTAINER)
                .withWorkloadType(WorkloadType.SQLDB)
                .withErrorDetails(Arrays.asList(new MabErrorInfo()))
                .withExtendedInfo(
                    new MabJobExtendedInfo()
                        .withTasksList(
                            Arrays
                                .asList(
                                    new MabJobTaskDetails()
                                        .withTaskId("nulaiywzejywhsl")
                                        .withStartTime(OffsetDateTime.parse("2021-06-09T06:05:44Z"))
                                        .withEndTime(OffsetDateTime.parse("2021-10-11T08:16:03Z"))
                                        .withDuration(Duration.parse("PT94H10M55S"))
                                        .withStatus("npdwr"),
                                    new MabJobTaskDetails()
                                        .withTaskId("afgfugsnn")
                                        .withStartTime(OffsetDateTime.parse("2021-08-26T04:30:17Z"))
                                        .withEndTime(OffsetDateTime.parse("2021-07-08T15:54:36Z"))
                                        .withDuration(Duration.parse("PT135H28M58S"))
                                        .withStatus("pococtfjgt"),
                                    new MabJobTaskDetails()
                                        .withTaskId("rjvzuyt")
                                        .withStartTime(OffsetDateTime.parse("2021-03-14T11:53:49Z"))
                                        .withEndTime(OffsetDateTime.parse("2021-04-19T09:03:23Z"))
                                        .withDuration(Duration.parse("PT181H51M44S"))
                                        .withStatus("olbauirop"),
                                    new MabJobTaskDetails()
                                        .withTaskId("nszonwpngaj")
                                        .withStartTime(OffsetDateTime.parse("2020-12-27T04:22:49Z"))
                                        .withEndTime(OffsetDateTime.parse("2021-06-01T23:38:48Z"))
                                        .withDuration(Duration.parse("PT189H58M33S"))
                                        .withStatus("rtmjfj")))
                        .withPropertyBag(
                            mapOf(
                                "nlusfnrd",
                                "cxlzhcoxovnekh",
                                "tjvidt",
                                "jxtxrdc",
                                "uwkasiz",
                                "gepuslvyjtc",
                                "qfecjxeygtuhx",
                                "esfuught"))
                        .withDynamicErrorMessage("cbuewmrswnjlxuz"));
        model = BinaryData.fromObject(model).toObject(MabJob.class);
        Assertions.assertEquals("wpusxjbaqehg", model.entityFriendlyName());
        Assertions.assertEquals(BackupManagementType.MAB, model.backupManagementType());
        Assertions.assertEquals("zjqatucoig", model.operation());
        Assertions.assertEquals("xncnwfe", model.status());
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-30T09:19:55Z"), model.startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-02T11:06:06Z"), model.endTime());
        Assertions.assertEquals("m", model.activityId());
        Assertions.assertEquals(Duration.parse("PT78H42M28S"), model.duration());
        Assertions.assertEquals(JobSupportedAction.CANCELLABLE, model.actionsInfo().get(0));
        Assertions.assertEquals("ubqmamh", model.mabServerName());
        Assertions.assertEquals(MabServerType.AZURE_SQL_CONTAINER, model.mabServerType());
        Assertions.assertEquals(WorkloadType.SQLDB, model.workloadType());
        Assertions.assertEquals("nulaiywzejywhsl", model.extendedInfo().tasksList().get(0).taskId());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-06-09T06:05:44Z"), model.extendedInfo().tasksList().get(0).startTime());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-10-11T08:16:03Z"), model.extendedInfo().tasksList().get(0).endTime());
        Assertions.assertEquals(Duration.parse("PT94H10M55S"), model.extendedInfo().tasksList().get(0).duration());
        Assertions.assertEquals("npdwr", model.extendedInfo().tasksList().get(0).status());
        Assertions.assertEquals("cxlzhcoxovnekh", model.extendedInfo().propertyBag().get("nlusfnrd"));
        Assertions.assertEquals("cbuewmrswnjlxuz", model.extendedInfo().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;
    }
}
