// 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.models.AzureIaaSvmProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasvmPolicyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.InstantRPAdditionalDetails;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.SchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.TieringMode;
import com.azure.resourcemanager.recoveryservicesbackup.models.TieringPolicy;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AzureIaaSvmProtectionPolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureIaaSvmProtectionPolicy model =
            BinaryData
                .fromString(
                    "{\"backupManagementType\":\"AzureIaasVM\",\"instantRPDetails\":{\"azureBackupRGNamePrefix\":\"yo\",\"azureBackupRGNameSuffix\":\"blgyavutpthj\"},\"schedulePolicy\":{\"schedulePolicyType\":\"SchedulePolicy\"},\"retentionPolicy\":{\"retentionPolicyType\":\"RetentionPolicy\"},\"tieringPolicy\":{\"iml\":{\"tieringMode\":\"Invalid\",\"duration\":1828523289,\"durationType\":\"Invalid\"},\"gxxlxsffgcvizq\":{\"tieringMode\":\"TierAfter\",\"duration\":1639942247,\"durationType\":\"Weeks\"}},\"instantRpRetentionRangeInDays\":514804559,\"timeZone\":\"vwlyoup\",\"policyType\":\"V1\",\"protectedItemsCount\":11112663,\"resourceGuardOperationRequests\":[\"bdyhgkfminsgowz\",\"ttsttktlahbqact\"]}")
                .toObject(AzureIaaSvmProtectionPolicy.class);
        Assertions.assertEquals(11112663, model.protectedItemsCount());
        Assertions.assertEquals("bdyhgkfminsgowz", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals("yo", model.instantRPDetails().azureBackupRGNamePrefix());
        Assertions.assertEquals("blgyavutpthj", model.instantRPDetails().azureBackupRGNameSuffix());
        Assertions.assertEquals(TieringMode.INVALID, model.tieringPolicy().get("iml").tieringMode());
        Assertions.assertEquals(1828523289, model.tieringPolicy().get("iml").duration());
        Assertions.assertEquals(RetentionDurationType.INVALID, model.tieringPolicy().get("iml").durationType());
        Assertions.assertEquals(514804559, model.instantRpRetentionRangeInDays());
        Assertions.assertEquals("vwlyoup", model.timeZone());
        Assertions.assertEquals(IaasvmPolicyType.V1, model.policyType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureIaaSvmProtectionPolicy model =
            new AzureIaaSvmProtectionPolicy()
                .withProtectedItemsCount(11112663)
                .withResourceGuardOperationRequests(Arrays.asList("bdyhgkfminsgowz", "ttsttktlahbqact"))
                .withInstantRPDetails(
                    new InstantRPAdditionalDetails()
                        .withAzureBackupRGNamePrefix("yo")
                        .withAzureBackupRGNameSuffix("blgyavutpthj"))
                .withSchedulePolicy(new SchedulePolicy())
                .withRetentionPolicy(new RetentionPolicy())
                .withTieringPolicy(
                    mapOf(
                        "iml",
                        new TieringPolicy()
                            .withTieringMode(TieringMode.INVALID)
                            .withDuration(1828523289)
                            .withDurationType(RetentionDurationType.INVALID),
                        "gxxlxsffgcvizq",
                        new TieringPolicy()
                            .withTieringMode(TieringMode.TIER_AFTER)
                            .withDuration(1639942247)
                            .withDurationType(RetentionDurationType.WEEKS)))
                .withInstantRpRetentionRangeInDays(514804559)
                .withTimeZone("vwlyoup")
                .withPolicyType(IaasvmPolicyType.V1);
        model = BinaryData.fromObject(model).toObject(AzureIaaSvmProtectionPolicy.class);
        Assertions.assertEquals(11112663, model.protectedItemsCount());
        Assertions.assertEquals("bdyhgkfminsgowz", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals("yo", model.instantRPDetails().azureBackupRGNamePrefix());
        Assertions.assertEquals("blgyavutpthj", model.instantRPDetails().azureBackupRGNameSuffix());
        Assertions.assertEquals(TieringMode.INVALID, model.tieringPolicy().get("iml").tieringMode());
        Assertions.assertEquals(1828523289, model.tieringPolicy().get("iml").duration());
        Assertions.assertEquals(RetentionDurationType.INVALID, model.tieringPolicy().get("iml").durationType());
        Assertions.assertEquals(514804559, model.instantRpRetentionRangeInDays());
        Assertions.assertEquals("vwlyoup", model.timeZone());
        Assertions.assertEquals(IaasvmPolicyType.V1, model.policyType());
    }

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