// 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.fluent.models.JobResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.BackupManagementType;
import com.azure.resourcemanager.recoveryservicesbackup.models.Job;
import com.azure.resourcemanager.recoveryservicesbackup.models.JobResourceList;
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 JobResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        JobResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"jobType\":\"Job\",\"entityFriendlyName\":\"lopwiyig\",\"backupManagementType\":\"MAB\",\"operation\":\"dwzbaiue\",\"status\":\"a\",\"startTime\":\"2021-03-01T01:27:20Z\",\"endTime\":\"2021-03-15T03:03:20Z\",\"activityId\":\"ped\"},\"eTag\":\"jn\",\"location\":\"bckhsmtxpsi\",\"tags\":{\"rdqmhjjdhtldwkyz\":\"fhvpesaps\",\"cwsvlxotog\":\"uutkncw\",\"o\":\"wrupqsxvnmicykvc\",\"vnotyfjfcnj\":\"eil\"},\"id\":\"k\",\"name\":\"nxdhbt\",\"type\":\"kphywpnvjto\"},{\"properties\":{\"jobType\":\"Job\",\"entityFriendlyName\":\"rmclfplphoxu\",\"backupManagementType\":\"DefaultBackup\",\"operation\":\"abgy\",\"status\":\"sbj\",\"startTime\":\"2021-11-02T03:38:26Z\",\"endTime\":\"2021-10-14T16:25:44Z\",\"activityId\":\"xywpmueefjzwfqkq\"},\"eTag\":\"ids\",\"location\":\"yonobgl\",\"tags\":{\"tlmoyrx\":\"qxtccmgyudx\"},\"id\":\"wfudwpzntxhdzhl\",\"name\":\"qj\",\"type\":\"hckfrlhrx\"}],\"nextLink\":\"kyv\"}")
                .toObject(JobResourceList.class);
        Assertions.assertEquals("kyv", model.nextLink());
        Assertions.assertEquals("bckhsmtxpsi", model.value().get(0).location());
        Assertions.assertEquals("fhvpesaps", model.value().get(0).tags().get("rdqmhjjdhtldwkyz"));
        Assertions.assertEquals("lopwiyig", model.value().get(0).properties().entityFriendlyName());
        Assertions.assertEquals(BackupManagementType.MAB, model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("dwzbaiue", model.value().get(0).properties().operation());
        Assertions.assertEquals("a", model.value().get(0).properties().status());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-03-01T01:27:20Z"), model.value().get(0).properties().startTime());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-03-15T03:03:20Z"), model.value().get(0).properties().endTime());
        Assertions.assertEquals("ped", model.value().get(0).properties().activityId());
        Assertions.assertEquals("jn", model.value().get(0).etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        JobResourceList model =
            new JobResourceList()
                .withNextLink("kyv")
                .withValue(
                    Arrays
                        .asList(
                            new JobResourceInner()
                                .withLocation("bckhsmtxpsi")
                                .withTags(
                                    mapOf(
                                        "rdqmhjjdhtldwkyz",
                                        "fhvpesaps",
                                        "cwsvlxotog",
                                        "uutkncw",
                                        "o",
                                        "wrupqsxvnmicykvc",
                                        "vnotyfjfcnj",
                                        "eil"))
                                .withProperties(
                                    new Job()
                                        .withEntityFriendlyName("lopwiyig")
                                        .withBackupManagementType(BackupManagementType.MAB)
                                        .withOperation("dwzbaiue")
                                        .withStatus("a")
                                        .withStartTime(OffsetDateTime.parse("2021-03-01T01:27:20Z"))
                                        .withEndTime(OffsetDateTime.parse("2021-03-15T03:03:20Z"))
                                        .withActivityId("ped"))
                                .withEtag("jn"),
                            new JobResourceInner()
                                .withLocation("yonobgl")
                                .withTags(mapOf("tlmoyrx", "qxtccmgyudx"))
                                .withProperties(
                                    new Job()
                                        .withEntityFriendlyName("rmclfplphoxu")
                                        .withBackupManagementType(BackupManagementType.DEFAULT_BACKUP)
                                        .withOperation("abgy")
                                        .withStatus("sbj")
                                        .withStartTime(OffsetDateTime.parse("2021-11-02T03:38:26Z"))
                                        .withEndTime(OffsetDateTime.parse("2021-10-14T16:25:44Z"))
                                        .withActivityId("xywpmueefjzwfqkq"))
                                .withEtag("ids")));
        model = BinaryData.fromObject(model).toObject(JobResourceList.class);
        Assertions.assertEquals("kyv", model.nextLink());
        Assertions.assertEquals("bckhsmtxpsi", model.value().get(0).location());
        Assertions.assertEquals("fhvpesaps", model.value().get(0).tags().get("rdqmhjjdhtldwkyz"));
        Assertions.assertEquals("lopwiyig", model.value().get(0).properties().entityFriendlyName());
        Assertions.assertEquals(BackupManagementType.MAB, model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("dwzbaiue", model.value().get(0).properties().operation());
        Assertions.assertEquals("a", model.value().get(0).properties().status());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-03-01T01:27:20Z"), model.value().get(0).properties().startTime());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-03-15T03:03:20Z"), model.value().get(0).properties().endTime());
        Assertions.assertEquals("ped", model.value().get(0).properties().activityId());
        Assertions.assertEquals("jn", model.value().get(0).etag());
    }

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