// 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.AzureWorkloadSqlPointInTimeRestoreRequest;
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.SqlDataDirectoryMapping;
import com.azure.resourcemanager.recoveryservicesbackup.models.SqlDataDirectoryType;
import com.azure.resourcemanager.recoveryservicesbackup.models.TargetRestoreInfo;
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 AzureWorkloadSqlPointInTimeRestoreRequestTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadSqlPointInTimeRestoreRequest model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadSQLPointInTimeRestoreRequest\",\"pointInTime\":\"2021-11-06T14:24:16Z\",\"shouldUseAlternateTargetLocation\":false,\"isNonRecoverable\":true,\"alternateDirectoryPaths\":[{\"mappingType\":\"Invalid\",\"sourceLogicalName\":\"luan\",\"sourcePath\":\"rfxeeebtij\",\"targetPath\":\"cvbmqzb\"},{\"mappingType\":\"Invalid\",\"sourceLogicalName\":\"aj\",\"sourcePath\":\"wxacevehj\",\"targetPath\":\"yxoaf\"},{\"mappingType\":\"Data\",\"sourceLogicalName\":\"lt\",\"sourcePath\":\"eyl\",\"targetPath\":\"mfgvxirpghriypo\"},{\"mappingType\":\"Log\",\"sourceLogicalName\":\"lqhykprlpyz\",\"sourcePath\":\"ciqdsme\",\"targetPath\":\"itdfuxtyasiib\"}],\"recoveryType\":\"AlternateLocation\",\"sourceResourceId\":\"nnust\",\"propertyBag\":{\"mgixhcmavmqfou\":\"jh\",\"cgyypro\":\"or\",\"undmbx\":\"wy\",\"ftpmdtzfjltfv\":\"ugcmjkavlgorb\"},\"targetInfo\":{\"overwriteOption\":\"Invalid\",\"containerId\":\"t\",\"databaseName\":\"p\",\"targetDirectoryForFileRestore\":\"pvpbdbzqgqqiheds\"},\"recoveryMode\":\"FileRecovery\",\"targetVirtualMachineId\":\"hmkyibc\"}")
                .toObject(AzureWorkloadSqlPointInTimeRestoreRequest.class);
        Assertions.assertEquals(RecoveryType.ALTERNATE_LOCATION, model.recoveryType());
        Assertions.assertEquals("nnust", model.sourceResourceId());
        Assertions.assertEquals("jh", model.propertyBag().get("mgixhcmavmqfou"));
        Assertions.assertEquals(OverwriteOptions.INVALID, model.targetInfo().overwriteOption());
        Assertions.assertEquals("t", model.targetInfo().containerId());
        Assertions.assertEquals("p", model.targetInfo().databaseName());
        Assertions.assertEquals("pvpbdbzqgqqiheds", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.FILE_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("hmkyibc", model.targetVirtualMachineId());
        Assertions.assertEquals(false, model.shouldUseAlternateTargetLocation());
        Assertions.assertEquals(true, model.isNonRecoverable());
        Assertions.assertEquals(SqlDataDirectoryType.INVALID, model.alternateDirectoryPaths().get(0).mappingType());
        Assertions.assertEquals("luan", model.alternateDirectoryPaths().get(0).sourceLogicalName());
        Assertions.assertEquals("rfxeeebtij", model.alternateDirectoryPaths().get(0).sourcePath());
        Assertions.assertEquals("cvbmqzb", model.alternateDirectoryPaths().get(0).targetPath());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-06T14:24:16Z"), model.pointInTime());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadSqlPointInTimeRestoreRequest model =
            new AzureWorkloadSqlPointInTimeRestoreRequest()
                .withRecoveryType(RecoveryType.ALTERNATE_LOCATION)
                .withSourceResourceId("nnust")
                .withPropertyBag(
                    mapOf("mgixhcmavmqfou", "jh", "cgyypro", "or", "undmbx", "wy", "ftpmdtzfjltfv", "ugcmjkavlgorb"))
                .withTargetInfo(
                    new TargetRestoreInfo()
                        .withOverwriteOption(OverwriteOptions.INVALID)
                        .withContainerId("t")
                        .withDatabaseName("p")
                        .withTargetDirectoryForFileRestore("pvpbdbzqgqqiheds"))
                .withRecoveryMode(RecoveryMode.FILE_RECOVERY)
                .withTargetVirtualMachineId("hmkyibc")
                .withShouldUseAlternateTargetLocation(false)
                .withIsNonRecoverable(true)
                .withAlternateDirectoryPaths(
                    Arrays
                        .asList(
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.INVALID)
                                .withSourceLogicalName("luan")
                                .withSourcePath("rfxeeebtij")
                                .withTargetPath("cvbmqzb"),
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.INVALID)
                                .withSourceLogicalName("aj")
                                .withSourcePath("wxacevehj")
                                .withTargetPath("yxoaf"),
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.DATA)
                                .withSourceLogicalName("lt")
                                .withSourcePath("eyl")
                                .withTargetPath("mfgvxirpghriypo"),
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.LOG)
                                .withSourceLogicalName("lqhykprlpyz")
                                .withSourcePath("ciqdsme")
                                .withTargetPath("itdfuxtyasiib")))
                .withPointInTime(OffsetDateTime.parse("2021-11-06T14:24:16Z"));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadSqlPointInTimeRestoreRequest.class);
        Assertions.assertEquals(RecoveryType.ALTERNATE_LOCATION, model.recoveryType());
        Assertions.assertEquals("nnust", model.sourceResourceId());
        Assertions.assertEquals("jh", model.propertyBag().get("mgixhcmavmqfou"));
        Assertions.assertEquals(OverwriteOptions.INVALID, model.targetInfo().overwriteOption());
        Assertions.assertEquals("t", model.targetInfo().containerId());
        Assertions.assertEquals("p", model.targetInfo().databaseName());
        Assertions.assertEquals("pvpbdbzqgqqiheds", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.FILE_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("hmkyibc", model.targetVirtualMachineId());
        Assertions.assertEquals(false, model.shouldUseAlternateTargetLocation());
        Assertions.assertEquals(true, model.isNonRecoverable());
        Assertions.assertEquals(SqlDataDirectoryType.INVALID, model.alternateDirectoryPaths().get(0).mappingType());
        Assertions.assertEquals("luan", model.alternateDirectoryPaths().get(0).sourceLogicalName());
        Assertions.assertEquals("rfxeeebtij", model.alternateDirectoryPaths().get(0).sourcePath());
        Assertions.assertEquals("cvbmqzb", model.alternateDirectoryPaths().get(0).targetPath());
        Assertions.assertEquals(OffsetDateTime.parse("2021-11-06T14:24:16Z"), 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;
    }
}
