// 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.AzureWorkloadSapHanaPointInTimeRestoreWithRehydrateRequest;
import com.azure.resourcemanager.recoveryservicesbackup.models.OverwriteOptions;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryMode;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryPointRehydrationInfo;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RehydrationPriority;
import com.azure.resourcemanager.recoveryservicesbackup.models.TargetRestoreInfo;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AzureWorkloadSapHanaPointInTimeRestoreWithRehydrateRequestTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadSapHanaPointInTimeRestoreWithRehydrateRequest model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadSAPHanaPointInTimeRestoreWithRehydrateRequest\",\"recoveryPointRehydrationInfo\":{\"rehydrationRetentionDuration\":\"sqxfxjelgcmpz\",\"rehydrationPriority\":\"High\"},\"pointInTime\":\"2021-11-04T06:03:59Z\",\"recoveryType\":\"OriginalLocation\",\"sourceResourceId\":\"w\",\"propertyBag\":{\"lbscmnlz\":\"acoyvivbsizusjs\",\"ehgmvflnwyv\":\"jiu\",\"utgqztwh\":\"kxrerlniylylyfwx\"},\"targetInfo\":{\"overwriteOption\":\"FailOnConflict\",\"containerId\":\"g\",\"databaseName\":\"jtcdxabbujftaben\",\"targetDirectoryForFileRestore\":\"klqpx\"},\"recoveryMode\":\"WorkloadRecovery\",\"targetVirtualMachineId\":\"feddwwnlza\"}")
                .toObject(AzureWorkloadSapHanaPointInTimeRestoreWithRehydrateRequest.class);
        Assertions.assertEquals(RecoveryType.ORIGINAL_LOCATION, model.recoveryType());
        Assertions.assertEquals("w", model.sourceResourceId());
        Assertions.assertEquals("acoyvivbsizusjs", model.propertyBag().get("lbscmnlz"));
        Assertions.assertEquals(OverwriteOptions.FAIL_ON_CONFLICT, model.targetInfo().overwriteOption());
        Assertions.assertEquals("g", model.targetInfo().containerId());
        Assertions.assertEquals("jtcdxabbujftaben", model.targetInfo().databaseName());
        Assertions.assertEquals("klqpx", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.WORKLOAD_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("feddwwnlza", model.targetVirtualMachineId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-04T06:03:59Z"), model.pointInTime());
        Assertions.assertEquals("sqxfxjelgcmpz", model.recoveryPointRehydrationInfo().rehydrationRetentionDuration());
        Assertions.assertEquals(RehydrationPriority.HIGH, model.recoveryPointRehydrationInfo().rehydrationPriority());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadSapHanaPointInTimeRestoreWithRehydrateRequest model =
            new AzureWorkloadSapHanaPointInTimeRestoreWithRehydrateRequest()
                .withRecoveryType(RecoveryType.ORIGINAL_LOCATION)
                .withSourceResourceId("w")
                .withPropertyBag(
                    mapOf("lbscmnlz", "acoyvivbsizusjs", "ehgmvflnwyv", "jiu", "utgqztwh", "kxrerlniylylyfwx"))
                .withTargetInfo(
                    new TargetRestoreInfo()
                        .withOverwriteOption(OverwriteOptions.FAIL_ON_CONFLICT)
                        .withContainerId("g")
                        .withDatabaseName("jtcdxabbujftaben")
                        .withTargetDirectoryForFileRestore("klqpx"))
                .withRecoveryMode(RecoveryMode.WORKLOAD_RECOVERY)
                .withTargetVirtualMachineId("feddwwnlza")
                .withPointInTime(OffsetDateTime.parse("2021-11-04T06:03:59Z"))
                .withRecoveryPointRehydrationInfo(
                    new RecoveryPointRehydrationInfo()
                        .withRehydrationRetentionDuration("sqxfxjelgcmpz")
                        .withRehydrationPriority(RehydrationPriority.HIGH));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadSapHanaPointInTimeRestoreWithRehydrateRequest.class);
        Assertions.assertEquals(RecoveryType.ORIGINAL_LOCATION, model.recoveryType());
        Assertions.assertEquals("w", model.sourceResourceId());
        Assertions.assertEquals("acoyvivbsizusjs", model.propertyBag().get("lbscmnlz"));
        Assertions.assertEquals(OverwriteOptions.FAIL_ON_CONFLICT, model.targetInfo().overwriteOption());
        Assertions.assertEquals("g", model.targetInfo().containerId());
        Assertions.assertEquals("jtcdxabbujftaben", model.targetInfo().databaseName());
        Assertions.assertEquals("klqpx", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.WORKLOAD_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("feddwwnlza", model.targetVirtualMachineId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-04T06:03:59Z"), model.pointInTime());
        Assertions.assertEquals("sqxfxjelgcmpz", model.recoveryPointRehydrationInfo().rehydrationRetentionDuration());
        Assertions.assertEquals(RehydrationPriority.HIGH, model.recoveryPointRehydrationInfo().rehydrationPriority());
    }

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