// 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.WorkloadItemResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectionStatus;
import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadItem;
import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadItemResourceList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class WorkloadItemResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WorkloadItemResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"workloadItemType\":\"WorkloadItem\",\"backupManagementType\":\"l\",\"workloadType\":\"tramxjez\",\"friendlyName\":\"wnwxuqlcvyd\",\"protectionState\":\"Protecting\"},\"eTag\":\"dooaojkniodko\",\"location\":\"ebwnujhe\",\"tags\":{\"wj\":\"bvdkcrodtjin\",\"f\":\"fltkacjv\",\"gaowpulpqblylsyx\":\"dlfoakggkfp\",\"xsdszuempsb\":\"qjnsjervtia\"},\"id\":\"kfzbeyvpnqicvi\",\"name\":\"v\",\"type\":\"jjxd\"},{\"properties\":{\"workloadItemType\":\"WorkloadItem\",\"backupManagementType\":\"uukzclewyhmlw\",\"workloadType\":\"ztzp\",\"friendlyName\":\"ncckw\",\"protectionState\":\"ProtectionFailed\"},\"eTag\":\"whxxbuyqax\",\"location\":\"feqztppriol\",\"tags\":{\"sobqw\":\"jaltolmnc\",\"vglsbjjca\":\"sdbnwdcfhucqdpf\",\"t\":\"vxb\"},\"id\":\"udutnco\",\"name\":\"mr\",\"type\":\"xqtvcofu\"}],\"nextLink\":\"lvkgju\"}")
                .toObject(WorkloadItemResourceList.class);
        Assertions.assertEquals("lvkgju", model.nextLink());
        Assertions.assertEquals("ebwnujhe", model.value().get(0).location());
        Assertions.assertEquals("bvdkcrodtjin", model.value().get(0).tags().get("wj"));
        Assertions.assertEquals("l", model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("tramxjez", model.value().get(0).properties().workloadType());
        Assertions.assertEquals("wnwxuqlcvyd", model.value().get(0).properties().friendlyName());
        Assertions.assertEquals(ProtectionStatus.PROTECTING, model.value().get(0).properties().protectionState());
        Assertions.assertEquals("dooaojkniodko", model.value().get(0).etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WorkloadItemResourceList model =
            new WorkloadItemResourceList()
                .withNextLink("lvkgju")
                .withValue(
                    Arrays
                        .asList(
                            new WorkloadItemResourceInner()
                                .withLocation("ebwnujhe")
                                .withTags(
                                    mapOf(
                                        "wj",
                                        "bvdkcrodtjin",
                                        "f",
                                        "fltkacjv",
                                        "gaowpulpqblylsyx",
                                        "dlfoakggkfp",
                                        "xsdszuempsb",
                                        "qjnsjervtia"))
                                .withProperties(
                                    new WorkloadItem()
                                        .withBackupManagementType("l")
                                        .withWorkloadType("tramxjez")
                                        .withFriendlyName("wnwxuqlcvyd")
                                        .withProtectionState(ProtectionStatus.PROTECTING))
                                .withEtag("dooaojkniodko"),
                            new WorkloadItemResourceInner()
                                .withLocation("feqztppriol")
                                .withTags(mapOf("sobqw", "jaltolmnc", "vglsbjjca", "sdbnwdcfhucqdpf", "t", "vxb"))
                                .withProperties(
                                    new WorkloadItem()
                                        .withBackupManagementType("uukzclewyhmlw")
                                        .withWorkloadType("ztzp")
                                        .withFriendlyName("ncckw")
                                        .withProtectionState(ProtectionStatus.PROTECTION_FAILED))
                                .withEtag("whxxbuyqax")));
        model = BinaryData.fromObject(model).toObject(WorkloadItemResourceList.class);
        Assertions.assertEquals("lvkgju", model.nextLink());
        Assertions.assertEquals("ebwnujhe", model.value().get(0).location());
        Assertions.assertEquals("bvdkcrodtjin", model.value().get(0).tags().get("wj"));
        Assertions.assertEquals("l", model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("tramxjez", model.value().get(0).properties().workloadType());
        Assertions.assertEquals("wnwxuqlcvyd", model.value().get(0).properties().friendlyName());
        Assertions.assertEquals(ProtectionStatus.PROTECTING, model.value().get(0).properties().protectionState());
        Assertions.assertEquals("dooaojkniodko", 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;
    }
}
