// 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 java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ResourceGuardResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ResourceGuardResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"Unknown\",\"allowAutoApprovals\":false,\"resourceGuardOperations\":[{\"vaultCriticalOperation\":\"qztpp\",\"requestResourceType\":\"o\"},{\"vaultCriticalOperation\":\"or\",\"requestResourceType\":\"lt\"},{\"vaultCriticalOperation\":\"mncwsobqwcsdb\",\"requestResourceType\":\"dcfhucqdpf\"}],\"vaultCriticalOperationExclusionList\":[\"lsbjjcanvxbv\",\"vudutncor\"],\"description\":\"lxqtvcofudfl\"},\"eTag\":\"gj\",\"location\":\"gdknnqv\",\"tags\":{\"yc\":\"nqntorudsgsahm\",\"u\":\"rauwjuetaebu\"},\"id\":\"dmovsm\",\"name\":\"l\",\"type\":\"wabm\"}")
                .toObject(ResourceGuardResourceInner.class);
        Assertions.assertEquals("gdknnqv", model.location());
        Assertions.assertEquals("nqntorudsgsahm", model.tags().get("yc"));
        Assertions.assertEquals("gj", model.etag());
        Assertions.assertEquals("lsbjjcanvxbv", model.properties().vaultCriticalOperationExclusionList().get(0));
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ResourceGuardResourceInner model =
            new ResourceGuardResourceInner()
                .withLocation("gdknnqv")
                .withTags(mapOf("yc", "nqntorudsgsahm", "u", "rauwjuetaebu"))
                .withEtag("gj")
                .withProperties(
                    new ResourceGuard()
                        .withVaultCriticalOperationExclusionList(Arrays.asList("lsbjjcanvxbv", "vudutncor")));
        model = BinaryData.fromObject(model).toObject(ResourceGuardResourceInner.class);
        Assertions.assertEquals("gdknnqv", model.location());
        Assertions.assertEquals("nqntorudsgsahm", model.tags().get("yc"));
        Assertions.assertEquals("gj", model.etag());
        Assertions.assertEquals("lsbjjcanvxbv", model.properties().vaultCriticalOperationExclusionList().get(0));
    }

    @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;
    }
}
