// 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.ProtectableContainerResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.BackupManagementType;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectableContainer;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectableContainerResourceList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ProtectableContainerResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProtectableContainerResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"protectableContainerType\":\"ProtectableContainer\",\"friendlyName\":\"e\",\"backupManagementType\":\"AzureBackupServer\",\"healthStatus\":\"rrwlquuijfqkace\",\"containerId\":\"ipfpubji\"},\"eTag\":\"wifto\",\"location\":\"qkvpuvksgplsakn\",\"tags\":{\"iyntorzihle\":\"synljphuopxodl\",\"yzrpzbchckqqzq\":\"sjswsrms\",\"ysuiizynkedya\":\"ox\"},\"id\":\"rwyhqmibzyhwitsm\",\"name\":\"pyy\",\"type\":\"pcdpumnz\"},{\"properties\":{\"protectableContainerType\":\"ProtectableContainer\",\"friendlyName\":\"z\",\"backupManagementType\":\"MAB\",\"healthStatus\":\"iknsorgjh\",\"containerId\":\"ldtlwwr\"},\"eTag\":\"dmtnc\",\"location\":\"ok\",\"tags\":{\"gsyocogj\":\"lxdy\",\"kvci\":\"tdtbnnhadooc\"},\"id\":\"hnvpamqgxq\",\"name\":\"u\",\"type\":\"zikywgg\"},{\"properties\":{\"protectableContainerType\":\"ProtectableContainer\",\"friendlyName\":\"lla\",\"backupManagementType\":\"AzureIaasVM\",\"healthStatus\":\"wuipiccjzkzivg\",\"containerId\":\"c\"},\"eTag\":\"y\",\"location\":\"hyrnxxmu\",\"tags\":{\"tchealmf\":\"ndrdvstkwq\",\"iohgwxrtfud\":\"tdaaygdvwvg\",\"mnpkukghimdblxg\":\"epxgyqagvr\",\"mszkkfo\":\"imfnjhfjx\"},\"id\":\"rey\",\"name\":\"kzikfjawneaivxwc\",\"type\":\"elpcirelsfeaenwa\"}],\"nextLink\":\"atklddxbjhwuaa\"}")
                .toObject(ProtectableContainerResourceList.class);
        Assertions.assertEquals("atklddxbjhwuaa", model.nextLink());
        Assertions.assertEquals("qkvpuvksgplsakn", model.value().get(0).location());
        Assertions.assertEquals("synljphuopxodl", model.value().get(0).tags().get("iyntorzihle"));
        Assertions.assertEquals("e", model.value().get(0).properties().friendlyName());
        Assertions
            .assertEquals(
                BackupManagementType.AZURE_BACKUP_SERVER, model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("rrwlquuijfqkace", model.value().get(0).properties().healthStatus());
        Assertions.assertEquals("ipfpubji", model.value().get(0).properties().containerId());
        Assertions.assertEquals("wifto", model.value().get(0).etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProtectableContainerResourceList model =
            new ProtectableContainerResourceList()
                .withNextLink("atklddxbjhwuaa")
                .withValue(
                    Arrays
                        .asList(
                            new ProtectableContainerResourceInner()
                                .withLocation("qkvpuvksgplsakn")
                                .withTags(
                                    mapOf(
                                        "iyntorzihle",
                                        "synljphuopxodl",
                                        "yzrpzbchckqqzq",
                                        "sjswsrms",
                                        "ysuiizynkedya",
                                        "ox"))
                                .withProperties(
                                    new ProtectableContainer()
                                        .withFriendlyName("e")
                                        .withBackupManagementType(BackupManagementType.AZURE_BACKUP_SERVER)
                                        .withHealthStatus("rrwlquuijfqkace")
                                        .withContainerId("ipfpubji"))
                                .withEtag("wifto"),
                            new ProtectableContainerResourceInner()
                                .withLocation("ok")
                                .withTags(mapOf("gsyocogj", "lxdy", "kvci", "tdtbnnhadooc"))
                                .withProperties(
                                    new ProtectableContainer()
                                        .withFriendlyName("z")
                                        .withBackupManagementType(BackupManagementType.MAB)
                                        .withHealthStatus("iknsorgjh")
                                        .withContainerId("ldtlwwr"))
                                .withEtag("dmtnc"),
                            new ProtectableContainerResourceInner()
                                .withLocation("hyrnxxmu")
                                .withTags(
                                    mapOf(
                                        "tchealmf",
                                        "ndrdvstkwq",
                                        "iohgwxrtfud",
                                        "tdaaygdvwvg",
                                        "mnpkukghimdblxg",
                                        "epxgyqagvr",
                                        "mszkkfo",
                                        "imfnjhfjx"))
                                .withProperties(
                                    new ProtectableContainer()
                                        .withFriendlyName("lla")
                                        .withBackupManagementType(BackupManagementType.AZURE_IAAS_VM)
                                        .withHealthStatus("wuipiccjzkzivg")
                                        .withContainerId("c"))
                                .withEtag("y")));
        model = BinaryData.fromObject(model).toObject(ProtectableContainerResourceList.class);
        Assertions.assertEquals("atklddxbjhwuaa", model.nextLink());
        Assertions.assertEquals("qkvpuvksgplsakn", model.value().get(0).location());
        Assertions.assertEquals("synljphuopxodl", model.value().get(0).tags().get("iyntorzihle"));
        Assertions.assertEquals("e", model.value().get(0).properties().friendlyName());
        Assertions
            .assertEquals(
                BackupManagementType.AZURE_BACKUP_SERVER, model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("rrwlquuijfqkace", model.value().get(0).properties().healthStatus());
        Assertions.assertEquals("ipfpubji", model.value().get(0).properties().containerId());
        Assertions.assertEquals("wifto", 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;
    }
}
