// 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.ProtectionPolicyResourceInner;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.ProtectionPolicyResourceList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ProtectionPolicyResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProtectionPolicyResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"backupManagementType\":\"ProtectionPolicy\",\"protectedItemsCount\":752212445,\"resourceGuardOperationRequests\":[]},\"eTag\":\"senhwlrs\",\"location\":\"frzpwvlqdqgb\",\"tags\":{\"vf\":\"lihkaetcktvfc\",\"xerf\":\"nkymuctqhjfbebrj\",\"phxepcyvahf\":\"wutttxfvjrbi\"},\"id\":\"ljkyqxjvuuj\",\"name\":\"gidokgjljyoxgvcl\",\"type\":\"bgsncghkjeszzhb\"},{\"properties\":{\"backupManagementType\":\"ProtectionPolicy\",\"protectedItemsCount\":1508297714,\"resourceGuardOperationRequests\":[]},\"eTag\":\"vgxbfs\",\"location\":\"xnehmpvec\",\"tags\":{\"flz\":\"debfqkkrbmpukgri\",\"qzahmgkbrp\":\"fbxzpuzycisp\",\"hibnuqqkpika\":\"y\",\"buynhijggm\":\"rgvtqag\"},\"id\":\"bfs\",\"name\":\"arbu\",\"type\":\"rcvpnazzmhjrunmp\"},{\"properties\":{\"backupManagementType\":\"ProtectionPolicy\",\"protectedItemsCount\":808779778,\"resourceGuardOperationRequests\":[]},\"eTag\":\"rbnlankxmyskp\",\"location\":\"henbtkcxywnytn\",\"tags\":{\"lhaaxdbabp\":\"nlqidybyxczf\"},\"id\":\"lwrq\",\"name\":\"fkts\",\"type\":\"hsucoc\"}],\"nextLink\":\"yyazttbt\"}")
                .toObject(ProtectionPolicyResourceList.class);
        Assertions.assertEquals("yyazttbt", model.nextLink());
        Assertions.assertEquals("frzpwvlqdqgb", model.value().get(0).location());
        Assertions.assertEquals("lihkaetcktvfc", model.value().get(0).tags().get("vf"));
        Assertions.assertEquals(752212445, model.value().get(0).properties().protectedItemsCount());
        Assertions.assertEquals("senhwlrs", model.value().get(0).etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProtectionPolicyResourceList model =
            new ProtectionPolicyResourceList()
                .withNextLink("yyazttbt")
                .withValue(
                    Arrays
                        .asList(
                            new ProtectionPolicyResourceInner()
                                .withLocation("frzpwvlqdqgb")
                                .withTags(
                                    mapOf(
                                        "vf",
                                        "lihkaetcktvfc",
                                        "xerf",
                                        "nkymuctqhjfbebrj",
                                        "phxepcyvahf",
                                        "wutttxfvjrbi"))
                                .withProperties(
                                    new ProtectionPolicy()
                                        .withProtectedItemsCount(752212445)
                                        .withResourceGuardOperationRequests(Arrays.asList()))
                                .withEtag("senhwlrs"),
                            new ProtectionPolicyResourceInner()
                                .withLocation("xnehmpvec")
                                .withTags(
                                    mapOf(
                                        "flz",
                                        "debfqkkrbmpukgri",
                                        "qzahmgkbrp",
                                        "fbxzpuzycisp",
                                        "hibnuqqkpika",
                                        "y",
                                        "buynhijggm",
                                        "rgvtqag"))
                                .withProperties(
                                    new ProtectionPolicy()
                                        .withProtectedItemsCount(1508297714)
                                        .withResourceGuardOperationRequests(Arrays.asList()))
                                .withEtag("vgxbfs"),
                            new ProtectionPolicyResourceInner()
                                .withLocation("henbtkcxywnytn")
                                .withTags(mapOf("lhaaxdbabp", "nlqidybyxczf"))
                                .withProperties(
                                    new ProtectionPolicy()
                                        .withProtectedItemsCount(808779778)
                                        .withResourceGuardOperationRequests(Arrays.asList()))
                                .withEtag("rbnlankxmyskp")));
        model = BinaryData.fromObject(model).toObject(ProtectionPolicyResourceList.class);
        Assertions.assertEquals("yyazttbt", model.nextLink());
        Assertions.assertEquals("frzpwvlqdqgb", model.value().get(0).location());
        Assertions.assertEquals("lihkaetcktvfc", model.value().get(0).tags().get("vf"));
        Assertions.assertEquals(752212445, model.value().get(0).properties().protectedItemsCount());
        Assertions.assertEquals("senhwlrs", 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;
    }
}
