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

public final class WorkloadProtectableItemResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        WorkloadProtectableItemResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"protectableItemType\":\"WorkloadProtectableItem\",\"backupManagementType\":\"hoftr\",\"workloadType\":\"equi\",\"friendlyName\":\"xicslfao\",\"protectionState\":\"ProtectionFailed\"},\"eTag\":\"yylhalnswhccsp\",\"location\":\"kaivwit\",\"tags\":{\"wem\":\"ywuggwoluhcz\",\"sbrgz\":\"ai\",\"ggicccnxqhue\":\"wmsweypqwd\"},\"id\":\"mkttlstvlzywem\",\"name\":\"zrncsdt\",\"type\":\"lusiy\"},{\"properties\":{\"protectableItemType\":\"WorkloadProtectableItem\",\"backupManagementType\":\"fgytguslfeadcyg\",\"workloadType\":\"kyhejhzisxgf\",\"friendlyName\":\"lolp\",\"protectionState\":\"Protecting\"},\"eTag\":\"r\",\"location\":\"qvujzraehtwdwrf\",\"tags\":{\"cdl\":\"iby\"},\"id\":\"h\",\"name\":\"hfwpracstwit\",\"type\":\"khevxccedc\"},{\"properties\":{\"protectableItemType\":\"WorkloadProtectableItem\",\"backupManagementType\":\"dyodnwzxltj\",\"workloadType\":\"nhltiugcxn\",\"friendlyName\":\"vwxqibyqunyo\",\"protectionState\":\"Protected\"},\"eTag\":\"mdjrkvfgbvfvp\",\"location\":\"bodacizsjq\",\"tags\":{\"ibqipqkg\":\"rribd\",\"mkrefajpjorwkq\":\"vxndz\",\"sjabibs\":\"yhgbijtjivfx\"},\"id\":\"stawfsdjpvkv\",\"name\":\"bjxbkzbzk\",\"type\":\"vncjabudurgk\"},{\"properties\":{\"protectableItemType\":\"WorkloadProtectableItem\",\"backupManagementType\":\"o\",\"workloadType\":\"hjjklff\",\"friendlyName\":\"ouw\",\"protectionState\":\"NotProtected\"},\"eTag\":\"rfzeey\",\"location\":\"bizikayuhq\",\"tags\":{\"bbqwrvtldg\":\"bs\",\"vm\":\"fp\"},\"id\":\"ipaslthaqfxssmwu\",\"name\":\"wbdsr\",\"type\":\"zpdrhneu\"}],\"nextLink\":\"wqkdwytisibi\"}")
                .toObject(WorkloadProtectableItemResourceList.class);
        Assertions.assertEquals("wqkdwytisibi", model.nextLink());
        Assertions.assertEquals("kaivwit", model.value().get(0).location());
        Assertions.assertEquals("ywuggwoluhcz", model.value().get(0).tags().get("wem"));
        Assertions.assertEquals("hoftr", model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("equi", model.value().get(0).properties().workloadType());
        Assertions.assertEquals("xicslfao", model.value().get(0).properties().friendlyName());
        Assertions
            .assertEquals(ProtectionStatus.PROTECTION_FAILED, model.value().get(0).properties().protectionState());
        Assertions.assertEquals("yylhalnswhccsp", model.value().get(0).etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        WorkloadProtectableItemResourceList model =
            new WorkloadProtectableItemResourceList()
                .withNextLink("wqkdwytisibi")
                .withValue(
                    Arrays
                        .asList(
                            new WorkloadProtectableItemResourceInner()
                                .withLocation("kaivwit")
                                .withTags(mapOf("wem", "ywuggwoluhcz", "sbrgz", "ai", "ggicccnxqhue", "wmsweypqwd"))
                                .withProperties(
                                    new WorkloadProtectableItem()
                                        .withBackupManagementType("hoftr")
                                        .withWorkloadType("equi")
                                        .withFriendlyName("xicslfao")
                                        .withProtectionState(ProtectionStatus.PROTECTION_FAILED))
                                .withEtag("yylhalnswhccsp"),
                            new WorkloadProtectableItemResourceInner()
                                .withLocation("qvujzraehtwdwrf")
                                .withTags(mapOf("cdl", "iby"))
                                .withProperties(
                                    new WorkloadProtectableItem()
                                        .withBackupManagementType("fgytguslfeadcyg")
                                        .withWorkloadType("kyhejhzisxgf")
                                        .withFriendlyName("lolp")
                                        .withProtectionState(ProtectionStatus.PROTECTING))
                                .withEtag("r"),
                            new WorkloadProtectableItemResourceInner()
                                .withLocation("bodacizsjq")
                                .withTags(
                                    mapOf("ibqipqkg", "rribd", "mkrefajpjorwkq", "vxndz", "sjabibs", "yhgbijtjivfx"))
                                .withProperties(
                                    new WorkloadProtectableItem()
                                        .withBackupManagementType("dyodnwzxltj")
                                        .withWorkloadType("nhltiugcxn")
                                        .withFriendlyName("vwxqibyqunyo")
                                        .withProtectionState(ProtectionStatus.PROTECTED))
                                .withEtag("mdjrkvfgbvfvp"),
                            new WorkloadProtectableItemResourceInner()
                                .withLocation("bizikayuhq")
                                .withTags(mapOf("bbqwrvtldg", "bs", "vm", "fp"))
                                .withProperties(
                                    new WorkloadProtectableItem()
                                        .withBackupManagementType("o")
                                        .withWorkloadType("hjjklff")
                                        .withFriendlyName("ouw")
                                        .withProtectionState(ProtectionStatus.NOT_PROTECTED))
                                .withEtag("rfzeey")));
        model = BinaryData.fromObject(model).toObject(WorkloadProtectableItemResourceList.class);
        Assertions.assertEquals("wqkdwytisibi", model.nextLink());
        Assertions.assertEquals("kaivwit", model.value().get(0).location());
        Assertions.assertEquals("ywuggwoluhcz", model.value().get(0).tags().get("wem"));
        Assertions.assertEquals("hoftr", model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("equi", model.value().get(0).properties().workloadType());
        Assertions.assertEquals("xicslfao", model.value().get(0).properties().friendlyName());
        Assertions
            .assertEquals(ProtectionStatus.PROTECTION_FAILED, model.value().get(0).properties().protectionState());
        Assertions.assertEquals("yylhalnswhccsp", 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;
    }
}
