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

public final class ProtectionIntentResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ProtectionIntentResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"protectionIntentItemType\":\"ProtectionIntent\",\"backupManagementType\":\"DefaultBackup\",\"sourceResourceId\":\"xhekuksjtxukcdm\",\"itemId\":\"rcryuanzwuxzdxta\",\"policyId\":\"lhmwhfpmrqobm\",\"protectionState\":\"Protected\"},\"eTag\":\"nryrtihf\",\"location\":\"tijbpzvgnwzsymgl\",\"tags\":{\"fcbjysagithxqha\":\"cyzkohdbihanuf\",\"cnpqxuhivyqniwby\":\"ifpikxwczby\",\"grtfwvu\":\"rkxvdum\",\"h\":\"xgaudccs\"},\"id\":\"jcny\",\"name\":\"j\",\"type\":\"kryhtnapczwlokj\"}")
                .toObject(ProtectionIntentResourceInner.class);
        Assertions.assertEquals("tijbpzvgnwzsymgl", model.location());
        Assertions.assertEquals("cyzkohdbihanuf", model.tags().get("fcbjysagithxqha"));
        Assertions.assertEquals(BackupManagementType.DEFAULT_BACKUP, model.properties().backupManagementType());
        Assertions.assertEquals("xhekuksjtxukcdm", model.properties().sourceResourceId());
        Assertions.assertEquals("rcryuanzwuxzdxta", model.properties().itemId());
        Assertions.assertEquals("lhmwhfpmrqobm", model.properties().policyId());
        Assertions.assertEquals(ProtectionStatus.PROTECTED, model.properties().protectionState());
        Assertions.assertEquals("nryrtihf", model.etag());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ProtectionIntentResourceInner model =
            new ProtectionIntentResourceInner()
                .withLocation("tijbpzvgnwzsymgl")
                .withTags(
                    mapOf(
                        "fcbjysagithxqha",
                        "cyzkohdbihanuf",
                        "cnpqxuhivyqniwby",
                        "ifpikxwczby",
                        "grtfwvu",
                        "rkxvdum",
                        "h",
                        "xgaudccs"))
                .withProperties(
                    new ProtectionIntent()
                        .withBackupManagementType(BackupManagementType.DEFAULT_BACKUP)
                        .withSourceResourceId("xhekuksjtxukcdm")
                        .withItemId("rcryuanzwuxzdxta")
                        .withPolicyId("lhmwhfpmrqobm")
                        .withProtectionState(ProtectionStatus.PROTECTED))
                .withEtag("nryrtihf");
        model = BinaryData.fromObject(model).toObject(ProtectionIntentResourceInner.class);
        Assertions.assertEquals("tijbpzvgnwzsymgl", model.location());
        Assertions.assertEquals("cyzkohdbihanuf", model.tags().get("fcbjysagithxqha"));
        Assertions.assertEquals(BackupManagementType.DEFAULT_BACKUP, model.properties().backupManagementType());
        Assertions.assertEquals("xhekuksjtxukcdm", model.properties().sourceResourceId());
        Assertions.assertEquals("rcryuanzwuxzdxta", model.properties().itemId());
        Assertions.assertEquals("lhmwhfpmrqobm", model.properties().policyId());
        Assertions.assertEquals(ProtectionStatus.PROTECTED, model.properties().protectionState());
        Assertions.assertEquals("nryrtihf", 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;
    }
}
