// 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.GenericProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.PolicyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.SchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.SubProtectionPolicy;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class GenericProtectionPolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        GenericProtectionPolicy model =
            BinaryData
                .fromString(
                    "{\"backupManagementType\":\"GenericProtectionPolicy\",\"subProtectionPolicy\":[{\"policyType\":\"SnapshotFull\",\"schedulePolicy\":{\"schedulePolicyType\":\"SchedulePolicy\"},\"retentionPolicy\":{\"retentionPolicyType\":\"RetentionPolicy\"},\"tieringPolicy\":{}},{\"policyType\":\"Log\",\"schedulePolicy\":{\"schedulePolicyType\":\"SchedulePolicy\"},\"retentionPolicy\":{\"retentionPolicyType\":\"RetentionPolicy\"},\"tieringPolicy\":{}},{\"policyType\":\"Full\",\"schedulePolicy\":{\"schedulePolicyType\":\"SchedulePolicy\"},\"retentionPolicy\":{\"retentionPolicyType\":\"RetentionPolicy\"},\"tieringPolicy\":{}},{\"policyType\":\"SnapshotCopyOnlyFull\",\"schedulePolicy\":{\"schedulePolicyType\":\"SchedulePolicy\"},\"retentionPolicy\":{\"retentionPolicyType\":\"RetentionPolicy\"},\"tieringPolicy\":{}}],\"timeZone\":\"ndvnoaml\",\"fabricName\":\"ehaohdjhh\",\"protectedItemsCount\":152942786,\"resourceGuardOperationRequests\":[\"xcoxpelnjet\",\"gltsxoat\",\"tgzpnpb\"]}")
                .toObject(GenericProtectionPolicy.class);
        Assertions.assertEquals(152942786, model.protectedItemsCount());
        Assertions.assertEquals("xcoxpelnjet", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(PolicyType.SNAPSHOT_FULL, model.subProtectionPolicy().get(0).policyType());
        Assertions.assertEquals("ndvnoaml", model.timeZone());
        Assertions.assertEquals("ehaohdjhh", model.fabricName());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        GenericProtectionPolicy model =
            new GenericProtectionPolicy()
                .withProtectedItemsCount(152942786)
                .withResourceGuardOperationRequests(Arrays.asList("xcoxpelnjet", "gltsxoat", "tgzpnpb"))
                .withSubProtectionPolicy(
                    Arrays
                        .asList(
                            new SubProtectionPolicy()
                                .withPolicyType(PolicyType.SNAPSHOT_FULL)
                                .withSchedulePolicy(new SchedulePolicy())
                                .withRetentionPolicy(new RetentionPolicy())
                                .withTieringPolicy(mapOf()),
                            new SubProtectionPolicy()
                                .withPolicyType(PolicyType.LOG)
                                .withSchedulePolicy(new SchedulePolicy())
                                .withRetentionPolicy(new RetentionPolicy())
                                .withTieringPolicy(mapOf()),
                            new SubProtectionPolicy()
                                .withPolicyType(PolicyType.FULL)
                                .withSchedulePolicy(new SchedulePolicy())
                                .withRetentionPolicy(new RetentionPolicy())
                                .withTieringPolicy(mapOf()),
                            new SubProtectionPolicy()
                                .withPolicyType(PolicyType.SNAPSHOT_COPY_ONLY_FULL)
                                .withSchedulePolicy(new SchedulePolicy())
                                .withRetentionPolicy(new RetentionPolicy())
                                .withTieringPolicy(mapOf())))
                .withTimeZone("ndvnoaml")
                .withFabricName("ehaohdjhh");
        model = BinaryData.fromObject(model).toObject(GenericProtectionPolicy.class);
        Assertions.assertEquals(152942786, model.protectedItemsCount());
        Assertions.assertEquals("xcoxpelnjet", model.resourceGuardOperationRequests().get(0));
        Assertions.assertEquals(PolicyType.SNAPSHOT_FULL, model.subProtectionPolicy().get(0).policyType());
        Assertions.assertEquals("ndvnoaml", model.timeZone());
        Assertions.assertEquals("ehaohdjhh", model.fabricName());
    }

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