// 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.AzureWorkloadSqlPointInTimeRecoveryPoint;
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureWorkloadSqlRecoveryPointExtendedInfo;
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 com.azure.resourcemanager.recoveryservicesbackup.models.SqlDataDirectory;
import com.azure.resourcemanager.recoveryservicesbackup.models.SqlDataDirectoryType;
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 AzureWorkloadSqlPointInTimeRecoveryPointTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadSqlPointInTimeRecoveryPoint model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadSQLPointInTimeRecoveryPoint\",\"timeRanges\":[{\"startTime\":\"2021-10-03T02:23:54Z\",\"endTime\":\"2021-03-25T06:29:19Z\"},{\"startTime\":\"2021-04-10T06:34:24Z\",\"endTime\":\"2021-04-19T03:15:10Z\"}],\"extendedInfo\":{\"dataDirectoryTimeInUTC\":\"2021-01-19T13:20:05Z\",\"dataDirectoryPaths\":[{\"type\":\"Log\",\"path\":\"xdza\",\"logicalName\":\"weoohguufuzboyj\"},{\"type\":\"Invalid\",\"path\":\"tzolbaemwmdxmeb\",\"logicalName\":\"scjpahlxv\"},{\"type\":\"Invalid\",\"path\":\"qxnmwmqt\",\"logicalName\":\"xyi\"},{\"type\":\"Log\",\"path\":\"vqcttadija\",\"logicalName\":\"kmr\"}]},\"recoveryPointTimeInUTC\":\"2021-09-17T14:17:20Z\",\"type\":\"Log\",\"recoveryPointTierDetails\":[{\"type\":\"ArchivedRP\",\"status\":\"Invalid\",\"extendedInfo\":{\"yxeb\":\"udqmeqwigpibudq\",\"tmhheioqa\":\"ybpmzznrtffyaq\"}},{\"type\":\"Invalid\",\"status\":\"Disabled\",\"extendedInfo\":{\"gql\":\"uqyrxpdl\",\"iosrsjuivfcdis\":\"ismjqfrddgamqu\",\"czexrxzbujrtrhqv\":\"irnxz\",\"zlrpiqywncvj\":\"revkhgnlnzo\"}},{\"type\":\"Invalid\",\"status\":\"Rehydrated\",\"extendedInfo\":{\"k\":\"zehtdhgb\",\"zmlovuanash\":\"reljeamur\",\"erbdk\":\"xlpm\"}}],\"recoveryPointMoveReadinessInfo\":{\"w\":{\"isReadyForMove\":false,\"additionalInfo\":\"zozsdbccxjmonfdg\"},\"qjctzenkeif\":{\"isReadyForMove\":true,\"additionalInfo\":\"uuwwltv\"},\"gsrboldforobw\":{\"isReadyForMove\":true,\"additionalInfo\":\"kdasvflyhbxcudch\"}},\"recoveryPointProperties\":{\"expiryTime\":\"izbfhfovvacq\",\"ruleName\":\"tuodxeszabbelaw\",\"isSoftDeleted\":false}}")
                .toObject(AzureWorkloadSqlPointInTimeRecoveryPoint.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-17T14:17:20Z"), model.recoveryPointTimeInUtc());
        Assertions.assertEquals(RestorePointType.LOG, model.type());
        Assertions.assertEquals(RecoveryPointTierType.ARCHIVED_RP, model.recoveryPointTierDetails().get(0).type());
        Assertions.assertEquals(RecoveryPointTierStatus.INVALID, model.recoveryPointTierDetails().get(0).status());
        Assertions.assertEquals("udqmeqwigpibudq", model.recoveryPointTierDetails().get(0).extendedInfo().get("yxeb"));
        Assertions.assertEquals(false, model.recoveryPointMoveReadinessInfo().get("w").isReadyForMove());
        Assertions.assertEquals("zozsdbccxjmonfdg", model.recoveryPointMoveReadinessInfo().get("w").additionalInfo());
        Assertions.assertEquals("izbfhfovvacq", model.recoveryPointProperties().expiryTime());
        Assertions.assertEquals("tuodxeszabbelaw", model.recoveryPointProperties().ruleName());
        Assertions.assertEquals(false, model.recoveryPointProperties().isSoftDeleted());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-01-19T13:20:05Z"), model.extendedInfo().dataDirectoryTimeInUtc());
        Assertions.assertEquals(SqlDataDirectoryType.LOG, model.extendedInfo().dataDirectoryPaths().get(0).type());
        Assertions.assertEquals("xdza", model.extendedInfo().dataDirectoryPaths().get(0).path());
        Assertions.assertEquals("weoohguufuzboyj", model.extendedInfo().dataDirectoryPaths().get(0).logicalName());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-03T02:23:54Z"), model.timeRanges().get(0).startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-25T06:29:19Z"), model.timeRanges().get(0).endTime());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadSqlPointInTimeRecoveryPoint model =
            new AzureWorkloadSqlPointInTimeRecoveryPoint()
                .withRecoveryPointTimeInUtc(OffsetDateTime.parse("2021-09-17T14:17:20Z"))
                .withType(RestorePointType.LOG)
                .withRecoveryPointTierDetails(
                    Arrays
                        .asList(
                            new RecoveryPointTierInformationV2()
                                .withType(RecoveryPointTierType.ARCHIVED_RP)
                                .withStatus(RecoveryPointTierStatus.INVALID)
                                .withExtendedInfo(mapOf("yxeb", "udqmeqwigpibudq", "tmhheioqa", "ybpmzznrtffyaq")),
                            new RecoveryPointTierInformationV2()
                                .withType(RecoveryPointTierType.INVALID)
                                .withStatus(RecoveryPointTierStatus.DISABLED)
                                .withExtendedInfo(
                                    mapOf(
                                        "gql",
                                        "uqyrxpdl",
                                        "iosrsjuivfcdis",
                                        "ismjqfrddgamqu",
                                        "czexrxzbujrtrhqv",
                                        "irnxz",
                                        "zlrpiqywncvj",
                                        "revkhgnlnzo")),
                            new RecoveryPointTierInformationV2()
                                .withType(RecoveryPointTierType.INVALID)
                                .withStatus(RecoveryPointTierStatus.REHYDRATED)
                                .withExtendedInfo(mapOf("k", "zehtdhgb", "zmlovuanash", "reljeamur", "erbdk", "xlpm"))))
                .withRecoveryPointMoveReadinessInfo(
                    mapOf(
                        "w",
                        new RecoveryPointMoveReadinessInfo()
                            .withIsReadyForMove(false)
                            .withAdditionalInfo("zozsdbccxjmonfdg"),
                        "qjctzenkeif",
                        new RecoveryPointMoveReadinessInfo().withIsReadyForMove(true).withAdditionalInfo("uuwwltv"),
                        "gsrboldforobw",
                        new RecoveryPointMoveReadinessInfo()
                            .withIsReadyForMove(true)
                            .withAdditionalInfo("kdasvflyhbxcudch")))
                .withRecoveryPointProperties(
                    new RecoveryPointProperties()
                        .withExpiryTime("izbfhfovvacq")
                        .withRuleName("tuodxeszabbelaw")
                        .withIsSoftDeleted(false))
                .withExtendedInfo(
                    new AzureWorkloadSqlRecoveryPointExtendedInfo()
                        .withDataDirectoryTimeInUtc(OffsetDateTime.parse("2021-01-19T13:20:05Z"))
                        .withDataDirectoryPaths(
                            Arrays
                                .asList(
                                    new SqlDataDirectory()
                                        .withType(SqlDataDirectoryType.LOG)
                                        .withPath("xdza")
                                        .withLogicalName("weoohguufuzboyj"),
                                    new SqlDataDirectory()
                                        .withType(SqlDataDirectoryType.INVALID)
                                        .withPath("tzolbaemwmdxmeb")
                                        .withLogicalName("scjpahlxv"),
                                    new SqlDataDirectory()
                                        .withType(SqlDataDirectoryType.INVALID)
                                        .withPath("qxnmwmqt")
                                        .withLogicalName("xyi"),
                                    new SqlDataDirectory()
                                        .withType(SqlDataDirectoryType.LOG)
                                        .withPath("vqcttadija")
                                        .withLogicalName("kmr"))))
                .withTimeRanges(
                    Arrays
                        .asList(
                            new PointInTimeRange()
                                .withStartTime(OffsetDateTime.parse("2021-10-03T02:23:54Z"))
                                .withEndTime(OffsetDateTime.parse("2021-03-25T06:29:19Z")),
                            new PointInTimeRange()
                                .withStartTime(OffsetDateTime.parse("2021-04-10T06:34:24Z"))
                                .withEndTime(OffsetDateTime.parse("2021-04-19T03:15:10Z"))));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadSqlPointInTimeRecoveryPoint.class);
        Assertions.assertEquals(OffsetDateTime.parse("2021-09-17T14:17:20Z"), model.recoveryPointTimeInUtc());
        Assertions.assertEquals(RestorePointType.LOG, model.type());
        Assertions.assertEquals(RecoveryPointTierType.ARCHIVED_RP, model.recoveryPointTierDetails().get(0).type());
        Assertions.assertEquals(RecoveryPointTierStatus.INVALID, model.recoveryPointTierDetails().get(0).status());
        Assertions.assertEquals("udqmeqwigpibudq", model.recoveryPointTierDetails().get(0).extendedInfo().get("yxeb"));
        Assertions.assertEquals(false, model.recoveryPointMoveReadinessInfo().get("w").isReadyForMove());
        Assertions.assertEquals("zozsdbccxjmonfdg", model.recoveryPointMoveReadinessInfo().get("w").additionalInfo());
        Assertions.assertEquals("izbfhfovvacq", model.recoveryPointProperties().expiryTime());
        Assertions.assertEquals("tuodxeszabbelaw", model.recoveryPointProperties().ruleName());
        Assertions.assertEquals(false, model.recoveryPointProperties().isSoftDeleted());
        Assertions
            .assertEquals(OffsetDateTime.parse("2021-01-19T13:20:05Z"), model.extendedInfo().dataDirectoryTimeInUtc());
        Assertions.assertEquals(SqlDataDirectoryType.LOG, model.extendedInfo().dataDirectoryPaths().get(0).type());
        Assertions.assertEquals("xdza", model.extendedInfo().dataDirectoryPaths().get(0).path());
        Assertions.assertEquals("weoohguufuzboyj", model.extendedInfo().dataDirectoryPaths().get(0).logicalName());
        Assertions.assertEquals(OffsetDateTime.parse("2021-10-03T02:23:54Z"), model.timeRanges().get(0).startTime());
        Assertions.assertEquals(OffsetDateTime.parse("2021-03-25T06:29:19Z"), 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;
    }
}
