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

public final class ProtectionPolicyResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProtectionPolicyResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"backupManagementType\":\"ProtectionPolicy\",\"protectedItemsCount\":1529613290,\"resourceGuardOperationRequests\":[\"edckzywbiexzfey\",\"eaxib\"]},\"eTag\":\"jwbhqwalmuz\",\"location\":\"oxaepd\",\"tags\":{\"bavxbniwdjswzt\":\"ancuxrhd\",\"xbzpfzab\":\"dbpgnxytxhp\"},\"id\":\"lcuhxwtctyqiklb\",\"name\":\"ovplw\",\"type\":\"bhvgy\"}")
                .toObject(ProtectionPolicyResourceInner.class);
        Assertions.assertEquals("oxaepd", model.location());
        Assertions.assertEquals("ancuxrhd", model.tags().get("bavxbniwdjswzt"));
        Assertions.assertEquals(1529613290, model.properties().protectedItemsCount());
        Assertions.assertEquals("edckzywbiexzfey", model.properties().resourceGuardOperationRequests().get(0));
        Assertions.assertEquals("jwbhqwalmuz", model.etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProtectionPolicyResourceInner model =
            new ProtectionPolicyResourceInner()
                .withLocation("oxaepd")
                .withTags(mapOf("bavxbniwdjswzt", "ancuxrhd", "xbzpfzab", "dbpgnxytxhp"))
                .withProperties(
                    new ProtectionPolicy()
                        .withProtectedItemsCount(1529613290)
                        .withResourceGuardOperationRequests(Arrays.asList("edckzywbiexzfey", "eaxib")))
                .withEtag("jwbhqwalmuz");
        model = BinaryData.fromObject(model).toObject(ProtectionPolicyResourceInner.class);
        Assertions.assertEquals("oxaepd", model.location());
        Assertions.assertEquals("ancuxrhd", model.tags().get("bavxbniwdjswzt"));
        Assertions.assertEquals(1529613290, model.properties().protectedItemsCount());
        Assertions.assertEquals("edckzywbiexzfey", model.properties().resourceGuardOperationRequests().get(0));
        Assertions.assertEquals("jwbhqwalmuz", model.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;
    }
}
