// 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.AzureWorkloadSapHanaPointInTimeRestoreRequest;
import com.azure.resourcemanager.recoveryservicesbackup.models.OverwriteOptions;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryMode;
import com.azure.resourcemanager.recoveryservicesbackup.models.RecoveryType;
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 AzureWorkloadSapHanaPointInTimeRestoreRequestTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadSapHanaPointInTimeRestoreRequest model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadSAPHanaPointInTimeRestoreRequest\",\"pointInTime\":\"2021-02-24T03:49:03Z\",\"recoveryType\":\"OriginalLocation\",\"sourceResourceId\":\"a\",\"propertyBag\":{\"uwprtujwsawd\":\"fdeesvecuijpxtx\",\"xavo\":\"jibabxvititvtze\"},\"targetInfo\":{\"overwriteOption\":\"FailOnConflict\",\"containerId\":\"ecdmdqbwpy\",\"databaseName\":\"tgsfja\",\"targetDirectoryForFileRestore\":\"slhhxudbxv\"},\"recoveryMode\":\"FileRecovery\",\"targetVirtualMachineId\":\"nsiru\"}")
                .toObject(AzureWorkloadSapHanaPointInTimeRestoreRequest.class);
        Assertions.assertEquals(RecoveryType.ORIGINAL_LOCATION, model.recoveryType());
        Assertions.assertEquals("a", model.sourceResourceId());
        Assertions.assertEquals("fdeesvecuijpxtx", model.propertyBag().get("uwprtujwsawd"));
        Assertions.assertEquals(OverwriteOptions.FAIL_ON_CONFLICT, model.targetInfo().overwriteOption());
        Assertions.assertEquals("ecdmdqbwpy", model.targetInfo().containerId());
        Assertions.assertEquals("tgsfja", model.targetInfo().databaseName());
        Assertions.assertEquals("slhhxudbxv", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.FILE_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("nsiru", model.targetVirtualMachineId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-24T03:49:03Z"), model.pointInTime());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadSapHanaPointInTimeRestoreRequest model =
            new AzureWorkloadSapHanaPointInTimeRestoreRequest()
                .withRecoveryType(RecoveryType.ORIGINAL_LOCATION)
                .withSourceResourceId("a")
                .withPropertyBag(mapOf("uwprtujwsawd", "fdeesvecuijpxtx", "xavo", "jibabxvititvtze"))
                .withTargetInfo(
                    new TargetRestoreInfo()
                        .withOverwriteOption(OverwriteOptions.FAIL_ON_CONFLICT)
                        .withContainerId("ecdmdqbwpy")
                        .withDatabaseName("tgsfja")
                        .withTargetDirectoryForFileRestore("slhhxudbxv"))
                .withRecoveryMode(RecoveryMode.FILE_RECOVERY)
                .withTargetVirtualMachineId("nsiru")
                .withPointInTime(OffsetDateTime.parse("2021-02-24T03:49:03Z"));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadSapHanaPointInTimeRestoreRequest.class);
        Assertions.assertEquals(RecoveryType.ORIGINAL_LOCATION, model.recoveryType());
        Assertions.assertEquals("a", model.sourceResourceId());
        Assertions.assertEquals("fdeesvecuijpxtx", model.propertyBag().get("uwprtujwsawd"));
        Assertions.assertEquals(OverwriteOptions.FAIL_ON_CONFLICT, model.targetInfo().overwriteOption());
        Assertions.assertEquals("ecdmdqbwpy", model.targetInfo().containerId());
        Assertions.assertEquals("tgsfja", model.targetInfo().databaseName());
        Assertions.assertEquals("slhhxudbxv", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.FILE_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("nsiru", model.targetVirtualMachineId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-02-24T03:49:03Z"), model.pointInTime());
    }

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