// 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.AzureWorkloadSapHanaPointInTimeRecoveryPoint;
import com.azure.resourcemanager.recoveryservicesbackup.models.PointInTimeRange;
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 AzureWorkloadSapHanaPointInTimeRecoveryPointTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadSapHanaPointInTimeRecoveryPoint model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadSAPHanaPointInTimeRecoveryPoint\",\"timeRanges\":[{\"startTime\":\"2021-05-10T19:57:54Z\",\"endTime\":\"2021-07-10T13:36:32Z\"},{\"startTime\":\"2021-03-06T13:14:28Z\",\"endTime\":\"2021-06-03T22:21:12Z\"},{\"startTime\":\"2021-04-26T07:00:30Z\",\"endTime\":\"2021-05-13T12:27Z\"},{\"startTime\":\"2021-09-07T02:46:57Z\",\"endTime\":\"2021-03-25T00:45:30Z\"}],\"recoveryPointTimeInUTC\":\"2020-12-28T00:28:07Z\",\"type\":\"SnapshotCopyOnlyFull\",\"recoveryPointTierDetails\":[{\"type\":\"HardenedRP\",\"status\":\"Rehydrated\",\"extendedInfo\":{\"moy\":\"hcans\",\"mf\":\"hlwigdivbkbxg\"}},{\"type\":\"InstantRP\",\"status\":\"Invalid\",\"extendedInfo\":{\"hzbezkgi\":\"vdaeyyguxakjsq\",\"vvjskgfmocwahp\":\"sidxasicdd\",\"eaahhvjhhn\":\"gat\",\"jjidjk\":\"kzyb\"}}],\"recoveryPointMoveReadinessInfo\":{\"ednljl\":{\"isReadyForMove\":true,\"additionalInfo\":\"vxevblb\"},\"nsmjbnkppxynen\":{\"isReadyForMove\":false,\"additionalInfo\":\"aulx\"},\"nsrmffeycx\":{\"isReadyForMove\":false,\"additionalInfo\":\"eizzgwk\"}},\"recoveryPointProperties\":{\"expiryTime\":\"piymerteea\",\"ruleName\":\"xqiekkkzddrtk\",\"isSoftDeleted\":false}}")
                .toObject(AzureWorkloadSapHanaPointInTimeRecoveryPoint.class);
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-28T00:28:07Z"), model.recoveryPointTimeInUtc());
        Assertions.assertEquals(RestorePointType.SNAPSHOT_COPY_ONLY_FULL, model.type());
        Assertions.assertEquals(RecoveryPointTierType.HARDENED_RP, model.recoveryPointTierDetails().get(0).type());
        Assertions.assertEquals(RecoveryPointTierStatus.REHYDRATED, model.recoveryPointTierDetails().get(0).status());
        Assertions.assertEquals("hcans", model.recoveryPointTierDetails().get(0).extendedInfo().get("moy"));
        Assertions.assertEquals(true, model.recoveryPointMoveReadinessInfo().get("ednljl").isReadyForMove());
        Assertions.assertEquals("vxevblb", model.recoveryPointMoveReadinessInfo().get("ednljl").additionalInfo());
        Assertions.assertEquals("piymerteea", model.recoveryPointProperties().expiryTime());
        Assertions.assertEquals("xqiekkkzddrtk", model.recoveryPointProperties().ruleName());
        Assertions.assertEquals(false, model.recoveryPointProperties().isSoftDeleted());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-10T19:57:54Z"), model.timeRanges().get(0).startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-10T13:36:32Z"), model.timeRanges().get(0).endTime());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadSapHanaPointInTimeRecoveryPoint model =
            new AzureWorkloadSapHanaPointInTimeRecoveryPoint()
                .withRecoveryPointTimeInUtc(OffsetDateTime.parse("2020-12-28T00:28:07Z"))
                .withType(RestorePointType.SNAPSHOT_COPY_ONLY_FULL)
                .withRecoveryPointTierDetails(
                    Arrays
                        .asList(
                            new RecoveryPointTierInformationV2()
                                .withType(RecoveryPointTierType.HARDENED_RP)
                                .withStatus(RecoveryPointTierStatus.REHYDRATED)
                                .withExtendedInfo(mapOf("moy", "hcans", "mf", "hlwigdivbkbxg")),
                            new RecoveryPointTierInformationV2()
                                .withType(RecoveryPointTierType.INSTANT_RP)
                                .withStatus(RecoveryPointTierStatus.INVALID)
                                .withExtendedInfo(
                                    mapOf(
                                        "hzbezkgi",
                                        "vdaeyyguxakjsq",
                                        "vvjskgfmocwahp",
                                        "sidxasicdd",
                                        "eaahhvjhhn",
                                        "gat",
                                        "jjidjk",
                                        "kzyb"))))
                .withRecoveryPointMoveReadinessInfo(
                    mapOf(
                        "ednljl",
                        new RecoveryPointMoveReadinessInfo().withIsReadyForMove(true).withAdditionalInfo("vxevblb"),
                        "nsmjbnkppxynen",
                        new RecoveryPointMoveReadinessInfo().withIsReadyForMove(false).withAdditionalInfo("aulx"),
                        "nsrmffeycx",
                        new RecoveryPointMoveReadinessInfo().withIsReadyForMove(false).withAdditionalInfo("eizzgwk")))
                .withRecoveryPointProperties(
                    new RecoveryPointProperties()
                        .withExpiryTime("piymerteea")
                        .withRuleName("xqiekkkzddrtk")
                        .withIsSoftDeleted(false))
                .withTimeRanges(
                    Arrays
                        .asList(
                            new PointInTimeRange()
                                .withStartTime(OffsetDateTime.parse("2021-05-10T19:57:54Z"))
                                .withEndTime(OffsetDateTime.parse("2021-07-10T13:36:32Z")),
                            new PointInTimeRange()
                                .withStartTime(OffsetDateTime.parse("2021-03-06T13:14:28Z"))
                                .withEndTime(OffsetDateTime.parse("2021-06-03T22:21:12Z")),
                            new PointInTimeRange()
                                .withStartTime(OffsetDateTime.parse("2021-04-26T07:00:30Z"))
                                .withEndTime(OffsetDateTime.parse("2021-05-13T12:27Z")),
                            new PointInTimeRange()
                                .withStartTime(OffsetDateTime.parse("2021-09-07T02:46:57Z"))
                                .withEndTime(OffsetDateTime.parse("2021-03-25T00:45:30Z"))));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadSapHanaPointInTimeRecoveryPoint.class);
        Assertions.assertEquals(OffsetDateTime.parse("2020-12-28T00:28:07Z"), model.recoveryPointTimeInUtc());
        Assertions.assertEquals(RestorePointType.SNAPSHOT_COPY_ONLY_FULL, model.type());
        Assertions.assertEquals(RecoveryPointTierType.HARDENED_RP, model.recoveryPointTierDetails().get(0).type());
        Assertions.assertEquals(RecoveryPointTierStatus.REHYDRATED, model.recoveryPointTierDetails().get(0).status());
        Assertions.assertEquals("hcans", model.recoveryPointTierDetails().get(0).extendedInfo().get("moy"));
        Assertions.assertEquals(true, model.recoveryPointMoveReadinessInfo().get("ednljl").isReadyForMove());
        Assertions.assertEquals("vxevblb", model.recoveryPointMoveReadinessInfo().get("ednljl").additionalInfo());
        Assertions.assertEquals("piymerteea", model.recoveryPointProperties().expiryTime());
        Assertions.assertEquals("xqiekkkzddrtk", model.recoveryPointProperties().ruleName());
        Assertions.assertEquals(false, model.recoveryPointProperties().isSoftDeleted());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-10T19:57:54Z"), model.timeRanges().get(0).startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-07-10T13:36:32Z"), model.timeRanges().get(0).endTime());
    }

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