// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.dataprotection.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.dataprotection.fluent.models.ResourceGuardResourceInner;
import com.azure.resourcemanager.dataprotection.models.ResourceGuard;
import com.azure.resourcemanager.dataprotection.models.ResourceGuardResourceList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ResourceGuardResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ResourceGuardResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"provisioningState\":\"Updating\",\"allowAutoApprovals\":true,\"resourceGuardOperations\":[],\"vaultCriticalOperationExclusionList\":[],\"description\":\"morppxebmnzbtbh\"},\"eTag\":\"glkfg\",\"location\":\"dneu\",\"tags\":{\"fikdowwqu\":\"phsdyhto\",\"zx\":\"v\",\"hcohfwdsjnk\":\"lvithhqzonosgg\",\"swacffgdkzz\":\"ljuti\"},\"id\":\"wkfvhqcrailvp\",\"name\":\"ppfufl\",\"type\":\"wdmhdlxyjrxs\"}],\"nextLink\":\"afcnih\"}")
                .toObject(ResourceGuardResourceList.class);
        Assertions.assertEquals("afcnih", model.nextLink());
        Assertions.assertEquals("dneu", model.value().get(0).location());
        Assertions.assertEquals("phsdyhto", model.value().get(0).tags().get("fikdowwqu"));
        Assertions.assertEquals("glkfg", model.value().get(0).etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ResourceGuardResourceList model =
            new ResourceGuardResourceList()
                .withNextLink("afcnih")
                .withValue(
                    Arrays
                        .asList(
                            new ResourceGuardResourceInner()
                                .withLocation("dneu")
                                .withTags(
                                    mapOf(
                                        "fikdowwqu",
                                        "phsdyhto",
                                        "zx",
                                        "v",
                                        "hcohfwdsjnk",
                                        "lvithhqzonosgg",
                                        "swacffgdkzz",
                                        "ljuti"))
                                .withEtag("glkfg")
                                .withProperties(
                                    new ResourceGuard().withVaultCriticalOperationExclusionList(Arrays.asList()))));
        model = BinaryData.fromObject(model).toObject(ResourceGuardResourceList.class);
        Assertions.assertEquals("afcnih", model.nextLink());
        Assertions.assertEquals("dneu", model.value().get(0).location());
        Assertions.assertEquals("phsdyhto", model.value().get(0).tags().get("fikdowwqu"));
        Assertions.assertEquals("glkfg", 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;
    }
}
