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

public final class SubProtectionPolicyTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        SubProtectionPolicy model =
            BinaryData
                .fromString(
                    "{\"policyType\":\"CopyOnlyFull\",\"schedulePolicy\":{\"schedulePolicyType\":\"SchedulePolicy\"},\"retentionPolicy\":{\"retentionPolicyType\":\"RetentionPolicy\"},\"tieringPolicy\":{\"qybaryeua\":{\"tieringMode\":\"TierRecommended\",\"duration\":1020341632,\"durationType\":\"Years\"}}}")
                .toObject(SubProtectionPolicy.class);
        Assertions.assertEquals(PolicyType.COPY_ONLY_FULL, model.policyType());
        Assertions.assertEquals(TieringMode.TIER_RECOMMENDED, model.tieringPolicy().get("qybaryeua").tieringMode());
        Assertions.assertEquals(1020341632, model.tieringPolicy().get("qybaryeua").duration());
        Assertions.assertEquals(RetentionDurationType.YEARS, model.tieringPolicy().get("qybaryeua").durationType());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        SubProtectionPolicy model =
            new SubProtectionPolicy()
                .withPolicyType(PolicyType.COPY_ONLY_FULL)
                .withSchedulePolicy(new SchedulePolicy())
                .withRetentionPolicy(new RetentionPolicy())
                .withTieringPolicy(
                    mapOf(
                        "qybaryeua",
                        new TieringPolicy()
                            .withTieringMode(TieringMode.TIER_RECOMMENDED)
                            .withDuration(1020341632)
                            .withDurationType(RetentionDurationType.YEARS)));
        model = BinaryData.fromObject(model).toObject(SubProtectionPolicy.class);
        Assertions.assertEquals(PolicyType.COPY_ONLY_FULL, model.policyType());
        Assertions.assertEquals(TieringMode.TIER_RECOMMENDED, model.tieringPolicy().get("qybaryeua").tieringMode());
        Assertions.assertEquals(1020341632, model.tieringPolicy().get("qybaryeua").duration());
        Assertions.assertEquals(RetentionDurationType.YEARS, model.tieringPolicy().get("qybaryeua").durationType());
    }

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