// 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.AzureWorkloadPointInTimeRestoreRequest;
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 AzureWorkloadPointInTimeRestoreRequestTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadPointInTimeRestoreRequest model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadPointInTimeRestoreRequest\",\"pointInTime\":\"2021-08-19T01:45:54Z\",\"recoveryType\":\"Invalid\",\"sourceResourceId\":\"neuvyinzqod\",\"propertyBag\":{\"xgsg\":\"gsh\",\"gzdjtxvzf\":\"p\",\"gafcqu\":\"bqvgaqv\",\"nwsdtutnwlduyc\":\"rdve\"},\"targetInfo\":{\"overwriteOption\":\"Overwrite\",\"containerId\":\"rmewipmve\",\"databaseName\":\"xukuqgsj\",\"targetDirectoryForFileRestore\":\"undxgketw\"},\"recoveryMode\":\"WorkloadRecovery\",\"targetVirtualMachineId\":\"jhfjmhvvmuvgpm\"}")
                .toObject(AzureWorkloadPointInTimeRestoreRequest.class);
        Assertions.assertEquals(RecoveryType.INVALID, model.recoveryType());
        Assertions.assertEquals("neuvyinzqod", model.sourceResourceId());
        Assertions.assertEquals("gsh", model.propertyBag().get("xgsg"));
        Assertions.assertEquals(OverwriteOptions.OVERWRITE, model.targetInfo().overwriteOption());
        Assertions.assertEquals("rmewipmve", model.targetInfo().containerId());
        Assertions.assertEquals("xukuqgsj", model.targetInfo().databaseName());
        Assertions.assertEquals("undxgketw", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.WORKLOAD_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("jhfjmhvvmuvgpm", model.targetVirtualMachineId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-19T01:45:54Z"), model.pointInTime());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadPointInTimeRestoreRequest model =
            new AzureWorkloadPointInTimeRestoreRequest()
                .withRecoveryType(RecoveryType.INVALID)
                .withSourceResourceId("neuvyinzqod")
                .withPropertyBag(mapOf("xgsg", "gsh", "gzdjtxvzf", "p", "gafcqu", "bqvgaqv", "nwsdtutnwlduyc", "rdve"))
                .withTargetInfo(
                    new TargetRestoreInfo()
                        .withOverwriteOption(OverwriteOptions.OVERWRITE)
                        .withContainerId("rmewipmve")
                        .withDatabaseName("xukuqgsj")
                        .withTargetDirectoryForFileRestore("undxgketw"))
                .withRecoveryMode(RecoveryMode.WORKLOAD_RECOVERY)
                .withTargetVirtualMachineId("jhfjmhvvmuvgpm")
                .withPointInTime(OffsetDateTime.parse("2021-08-19T01:45:54Z"));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadPointInTimeRestoreRequest.class);
        Assertions.assertEquals(RecoveryType.INVALID, model.recoveryType());
        Assertions.assertEquals("neuvyinzqod", model.sourceResourceId());
        Assertions.assertEquals("gsh", model.propertyBag().get("xgsg"));
        Assertions.assertEquals(OverwriteOptions.OVERWRITE, model.targetInfo().overwriteOption());
        Assertions.assertEquals("rmewipmve", model.targetInfo().containerId());
        Assertions.assertEquals("xukuqgsj", model.targetInfo().databaseName());
        Assertions.assertEquals("undxgketw", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.WORKLOAD_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("jhfjmhvvmuvgpm", model.targetVirtualMachineId());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-19T01:45:54Z"), 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;
    }
}
