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

public final class ProtectionContainerResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProtectionContainerResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"containerType\":\"ProtectionContainer\",\"friendlyName\":\"igrjguufzdm\",\"backupManagementType\":\"AzureSql\",\"registrationStatus\":\"fi\",\"healthStatus\":\"hbotzingamvppho\",\"protectableObjectType\":\"qzudphq\"},\"eTag\":\"vdkfwynwcvtbvk\",\"location\":\"yhmtnvyqiat\",\"tags\":{\"zcjaesgvvsccy\":\"pcnp\"},\"id\":\"jguq\",\"name\":\"hwyg\",\"type\":\"lvdnkfx\"},{\"properties\":{\"containerType\":\"ProtectionContainer\",\"friendlyName\":\"mdwzrmuhapfcqdps\",\"backupManagementType\":\"AzureWorkload\",\"registrationStatus\":\"psvuoymgc\",\"healthStatus\":\"lvez\",\"protectableObjectType\":\"pqlmfe\"},\"eTag\":\"erqwkyhkobopg\",\"location\":\"edkowepbqpcrfk\",\"tags\":{\"khtj\":\"csnjvcdwxlpqekft\",\"ngwfqatm\":\"y\",\"szywkbirryu\":\"dhtmdvypgikd\",\"nrvgoupmfiibfgg\":\"hlhkjoqrvqqaatj\"},\"id\":\"ioolvrwxkvtkkgll\",\"name\":\"wjygvjayvblmhvk\",\"type\":\"uhbxvvy\"}],\"nextLink\":\"s\"}")
                .toObject(ProtectionContainerResourceList.class);
        Assertions.assertEquals("s", model.nextLink());
        Assertions.assertEquals("yhmtnvyqiat", model.value().get(0).location());
        Assertions.assertEquals("pcnp", model.value().get(0).tags().get("zcjaesgvvsccy"));
        Assertions.assertEquals("igrjguufzdm", model.value().get(0).properties().friendlyName());
        Assertions
            .assertEquals(BackupManagementType.AZURE_SQL, model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("fi", model.value().get(0).properties().registrationStatus());
        Assertions.assertEquals("hbotzingamvppho", model.value().get(0).properties().healthStatus());
        Assertions.assertEquals("qzudphq", model.value().get(0).properties().protectableObjectType());
        Assertions.assertEquals("vdkfwynwcvtbvk", model.value().get(0).etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProtectionContainerResourceList model =
            new ProtectionContainerResourceList()
                .withNextLink("s")
                .withValue(
                    Arrays
                        .asList(
                            new ProtectionContainerResourceInner()
                                .withLocation("yhmtnvyqiat")
                                .withTags(mapOf("zcjaesgvvsccy", "pcnp"))
                                .withProperties(
                                    new ProtectionContainer()
                                        .withFriendlyName("igrjguufzdm")
                                        .withBackupManagementType(BackupManagementType.AZURE_SQL)
                                        .withRegistrationStatus("fi")
                                        .withHealthStatus("hbotzingamvppho")
                                        .withProtectableObjectType("qzudphq"))
                                .withEtag("vdkfwynwcvtbvk"),
                            new ProtectionContainerResourceInner()
                                .withLocation("edkowepbqpcrfk")
                                .withTags(
                                    mapOf(
                                        "khtj",
                                        "csnjvcdwxlpqekft",
                                        "ngwfqatm",
                                        "y",
                                        "szywkbirryu",
                                        "dhtmdvypgikd",
                                        "nrvgoupmfiibfgg",
                                        "hlhkjoqrvqqaatj"))
                                .withProperties(
                                    new ProtectionContainer()
                                        .withFriendlyName("mdwzrmuhapfcqdps")
                                        .withBackupManagementType(BackupManagementType.AZURE_WORKLOAD)
                                        .withRegistrationStatus("psvuoymgc")
                                        .withHealthStatus("lvez")
                                        .withProtectableObjectType("pqlmfe"))
                                .withEtag("erqwkyhkobopg")));
        model = BinaryData.fromObject(model).toObject(ProtectionContainerResourceList.class);
        Assertions.assertEquals("s", model.nextLink());
        Assertions.assertEquals("yhmtnvyqiat", model.value().get(0).location());
        Assertions.assertEquals("pcnp", model.value().get(0).tags().get("zcjaesgvvsccy"));
        Assertions.assertEquals("igrjguufzdm", model.value().get(0).properties().friendlyName());
        Assertions
            .assertEquals(BackupManagementType.AZURE_SQL, model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("fi", model.value().get(0).properties().registrationStatus());
        Assertions.assertEquals("hbotzingamvppho", model.value().get(0).properties().healthStatus());
        Assertions.assertEquals("qzudphq", model.value().get(0).properties().protectableObjectType());
        Assertions.assertEquals("vdkfwynwcvtbvk", 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;
    }
}
