// 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.AzureWorkloadRecoveryPoint;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryPointMoveReadinessInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryPointProperties;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryPointTierInformationV2;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryPointTierStatus;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryPointTierType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RestorePointType;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AzureWorkloadRecoveryPointTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadRecoveryPoint model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadRecoveryPoint\",\"recoveryPointTimeInUTC\":\"2021-10-20T18:11:07Z\",\"type\":\"Incremental\",\"recoveryPointTierDetails\":[{\"type\":\"HardenedRP\",\"status\":\"Disabled\",\"extendedInfo\":{\"dgfcwqmp\":\"tpkxztmoobklft\"}}],\"recoveryPointMoveReadinessInfo\":{\"ohu\":{\"isReadyForMove\":false,\"additionalInfo\":\"hemjy\"},\"culkbawpfaj\":{\"isReadyForMove\":false,\"additionalInfo\":\"wkozz\"},\"kcdmxzrpoaimln\":{\"isReadyForMove\":true,\"additionalInfo\":\"tlwtjjguktalhsn\"}},\"recoveryPointProperties\":{\"expiryTime\":\"aomylwea\",\"ruleName\":\"lcsethwwnpj\",\"isSoftDeleted\":false}}")
                .toObject(AzureWorkloadRecoveryPoint.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-20T18:11:07Z"), model.recoveryPointTimeInUtc());
        Assertions.assertEquals(RestorePointType.INCREMENTAL, model.type());
        Assertions.assertEquals(RecoveryPointTierType.HARDENED_RP, model.recoveryPointTierDetails().get(0).type());
        Assertions.assertEquals(RecoveryPointTierStatus.DISABLED, model.recoveryPointTierDetails().get(0).status());
        Assertions
            .assertEquals("tpkxztmoobklft", model.recoveryPointTierDetails().get(0).extendedInfo().get("dgfcwqmp"));
        Assertions.assertEquals(false, model.recoveryPointMoveReadinessInfo().get("ohu").isReadyForMove());
        Assertions.assertEquals("hemjy", model.recoveryPointMoveReadinessInfo().get("ohu").additionalInfo());
        Assertions.assertEquals("aomylwea", model.recoveryPointProperties().expiryTime());
        Assertions.assertEquals("lcsethwwnpj", model.recoveryPointProperties().ruleName());
        Assertions.assertEquals(false, model.recoveryPointProperties().isSoftDeleted());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadRecoveryPoint model =
            new AzureWorkloadRecoveryPoint()
                .withRecoveryPointTimeInUtc(OffsetDateTime.parse("2021-10-20T18:11:07Z"))
                .withType(RestorePointType.INCREMENTAL)
                .withRecoveryPointTierDetails(
                    Arrays
                        .asList(
                            new RecoveryPointTierInformationV2()
                                .withType(RecoveryPointTierType.HARDENED_RP)
                                .withStatus(RecoveryPointTierStatus.DISABLED)
                                .withExtendedInfo(mapOf("dgfcwqmp", "tpkxztmoobklft"))))
                .withRecoveryPointMoveReadinessInfo(
                    mapOf(
                        "ohu",
                        new RecoveryPointMoveReadinessInfo().withIsReadyForMove(false).withAdditionalInfo("hemjy"),
                        "culkbawpfaj",
                        new RecoveryPointMoveReadinessInfo().withIsReadyForMove(false).withAdditionalInfo("wkozz"),
                        "kcdmxzrpoaimln",
                        new RecoveryPointMoveReadinessInfo()
                            .withIsReadyForMove(true)
                            .withAdditionalInfo("tlwtjjguktalhsn")))
                .withRecoveryPointProperties(
                    new RecoveryPointProperties()
                        .withExpiryTime("aomylwea")
                        .withRuleName("lcsethwwnpj")
                        .withIsSoftDeleted(false));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadRecoveryPoint.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-20T18:11:07Z"), model.recoveryPointTimeInUtc());
        Assertions.assertEquals(RestorePointType.INCREMENTAL, model.type());
        Assertions.assertEquals(RecoveryPointTierType.HARDENED_RP, model.recoveryPointTierDetails().get(0).type());
        Assertions.assertEquals(RecoveryPointTierStatus.DISABLED, model.recoveryPointTierDetails().get(0).status());
        Assertions
            .assertEquals("tpkxztmoobklft", model.recoveryPointTierDetails().get(0).extendedInfo().get("dgfcwqmp"));
        Assertions.assertEquals(false, model.recoveryPointMoveReadinessInfo().get("ohu").isReadyForMove());
        Assertions.assertEquals("hemjy", model.recoveryPointMoveReadinessInfo().get("ohu").additionalInfo());
        Assertions.assertEquals("aomylwea", model.recoveryPointProperties().expiryTime());
        Assertions.assertEquals("lcsethwwnpj", model.recoveryPointProperties().ruleName());
        Assertions.assertEquals(false, model.recoveryPointProperties().isSoftDeleted());
    }

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