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

public final class ProtectionIntentResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProtectionIntentResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"protectionIntentItemType\":\"ProtectionIntent\",\"backupManagementType\":\"MAB\",\"sourceResourceId\":\"wixjsprozvcp\",\"itemId\":\"eg\",\"policyId\":\"wmfdatscmdvpjhul\",\"protectionState\":\"Protected\"},\"eTag\":\"mkjozkrwf\",\"location\":\"dio\",\"tags\":{\"yoqpsoaccta\":\"slwejdpvw\",\"lahbcryff\":\"akl\",\"xpaojakhmsbz\":\"fdosyg\"},\"id\":\"hcrzevd\",\"name\":\"hlxaolthqtr\",\"type\":\"qjbpfzfsin\"},{\"properties\":{\"protectionIntentItemType\":\"ProtectionIntent\",\"backupManagementType\":\"AzureBackupServer\",\"sourceResourceId\":\"jrwzox\",\"itemId\":\"tfell\",\"policyId\":\"fziton\",\"protectionState\":\"ProtectionFailed\"},\"eTag\":\"pjkjlxofpdv\",\"location\":\"pfxxy\",\"tags\":{\"mayhuybbkpodepoo\":\"i\",\"rxzxtheo\":\"inuvamiheogn\",\"cciqihnhungbwjz\":\"usivye\"},\"id\":\"nfygxgispemvtz\",\"name\":\"kufubljo\",\"type\":\"xqeofjaeqjhqjba\"}],\"nextLink\":\"msmjqulngsntn\"}")
                .toObject(ProtectionIntentResourceList.class);
        Assertions.assertEquals("msmjqulngsntn", model.nextLink());
        Assertions.assertEquals("dio", model.value().get(0).location());
        Assertions.assertEquals("slwejdpvw", model.value().get(0).tags().get("yoqpsoaccta"));
        Assertions.assertEquals(BackupManagementType.MAB, model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("wixjsprozvcp", model.value().get(0).properties().sourceResourceId());
        Assertions.assertEquals("eg", model.value().get(0).properties().itemId());
        Assertions.assertEquals("wmfdatscmdvpjhul", model.value().get(0).properties().policyId());
        Assertions.assertEquals(ProtectionStatus.PROTECTED, model.value().get(0).properties().protectionState());
        Assertions.assertEquals("mkjozkrwf", model.value().get(0).etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProtectionIntentResourceList model =
            new ProtectionIntentResourceList()
                .withNextLink("msmjqulngsntn")
                .withValue(
                    Arrays
                        .asList(
                            new ProtectionIntentResourceInner()
                                .withLocation("dio")
                                .withTags(
                                    mapOf("yoqpsoaccta", "slwejdpvw", "lahbcryff", "akl", "xpaojakhmsbz", "fdosyg"))
                                .withProperties(
                                    new ProtectionIntent()
                                        .withBackupManagementType(BackupManagementType.MAB)
                                        .withSourceResourceId("wixjsprozvcp")
                                        .withItemId("eg")
                                        .withPolicyId("wmfdatscmdvpjhul")
                                        .withProtectionState(ProtectionStatus.PROTECTED))
                                .withEtag("mkjozkrwf"),
                            new ProtectionIntentResourceInner()
                                .withLocation("pfxxy")
                                .withTags(
                                    mapOf(
                                        "mayhuybbkpodepoo",
                                        "i",
                                        "rxzxtheo",
                                        "inuvamiheogn",
                                        "cciqihnhungbwjz",
                                        "usivye"))
                                .withProperties(
                                    new ProtectionIntent()
                                        .withBackupManagementType(BackupManagementType.AZURE_BACKUP_SERVER)
                                        .withSourceResourceId("jrwzox")
                                        .withItemId("tfell")
                                        .withPolicyId("fziton")
                                        .withProtectionState(ProtectionStatus.PROTECTION_FAILED))
                                .withEtag("pjkjlxofpdv")));
        model = BinaryData.fromObject(model).toObject(ProtectionIntentResourceList.class);
        Assertions.assertEquals("msmjqulngsntn", model.nextLink());
        Assertions.assertEquals("dio", model.value().get(0).location());
        Assertions.assertEquals("slwejdpvw", model.value().get(0).tags().get("yoqpsoaccta"));
        Assertions.assertEquals(BackupManagementType.MAB, model.value().get(0).properties().backupManagementType());
        Assertions.assertEquals("wixjsprozvcp", model.value().get(0).properties().sourceResourceId());
        Assertions.assertEquals("eg", model.value().get(0).properties().itemId());
        Assertions.assertEquals("wmfdatscmdvpjhul", model.value().get(0).properties().policyId());
        Assertions.assertEquals(ProtectionStatus.PROTECTED, model.value().get(0).properties().protectionState());
        Assertions.assertEquals("mkjozkrwf", 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;
    }
}
