// 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.AzureWorkloadSqlPointInTimeRestoreWithRehydrateRequest;
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.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 AzureWorkloadSqlPointInTimeRestoreWithRehydrateRequestTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadSqlPointInTimeRestoreWithRehydrateRequest model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadSQLPointInTimeRestoreWithRehydrateRequest\",\"recoveryPointRehydrationInfo\":{\"rehydrationRetentionDuration\":\"hychocokuleh\",\"rehydrationPriority\":\"High\"},\"pointInTime\":\"2021-08-13T07:45:29Z\",\"shouldUseAlternateTargetLocation\":false,\"isNonRecoverable\":false,\"alternateDirectoryPaths\":[{\"mappingType\":\"Log\",\"sourceLogicalName\":\"kphyjdxrav\",\"sourcePath\":\"qdbrxmrgc\",\"targetPath\":\"apx\"}],\"recoveryType\":\"Invalid\",\"sourceResourceId\":\"jjk\",\"propertyBag\":{\"oycblevpmc\":\"buscgduus\",\"kzzltafhbzf\":\"ujyxkyxlzgsj\"},\"targetInfo\":{\"overwriteOption\":\"Overwrite\",\"containerId\":\"bjlzqsczpgvdwn\",\"databaseName\":\"fdqwowftpt\",\"targetDirectoryForFileRestore\":\"wjtkschgcgqyhl\"},\"recoveryMode\":\"WorkloadRecovery\",\"targetVirtualMachineId\":\"q\"}")
                .toObject(AzureWorkloadSqlPointInTimeRestoreWithRehydrateRequest.class);
        Assertions.assertEquals(RecoveryType.INVALID, model.recoveryType());
        Assertions.assertEquals("jjk", model.sourceResourceId());
        Assertions.assertEquals("buscgduus", model.propertyBag().get("oycblevpmc"));
        Assertions.assertEquals(OverwriteOptions.OVERWRITE, model.targetInfo().overwriteOption());
        Assertions.assertEquals("bjlzqsczpgvdwn", model.targetInfo().containerId());
        Assertions.assertEquals("fdqwowftpt", model.targetInfo().databaseName());
        Assertions.assertEquals("wjtkschgcgqyhl", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.WORKLOAD_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("q", model.targetVirtualMachineId());
        Assertions.assertEquals(false, model.shouldUseAlternateTargetLocation());
        Assertions.assertEquals(false, model.isNonRecoverable());
        Assertions.assertEquals(SqlDataDirectoryType.LOG, model.alternateDirectoryPaths().get(0).mappingType());
        Assertions.assertEquals("kphyjdxrav", model.alternateDirectoryPaths().get(0).sourceLogicalName());
        Assertions.assertEquals("qdbrxmrgc", model.alternateDirectoryPaths().get(0).sourcePath());
        Assertions.assertEquals("apx", model.alternateDirectoryPaths().get(0).targetPath());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-13T07:45:29Z"), model.pointInTime());
        Assertions.assertEquals("hychocokuleh", model.recoveryPointRehydrationInfo().rehydrationRetentionDuration());
        Assertions.assertEquals(RehydrationPriority.HIGH, model.recoveryPointRehydrationInfo().rehydrationPriority());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadSqlPointInTimeRestoreWithRehydrateRequest model =
            new AzureWorkloadSqlPointInTimeRestoreWithRehydrateRequest()
                .withRecoveryType(RecoveryType.INVALID)
                .withSourceResourceId("jjk")
                .withPropertyBag(mapOf("oycblevpmc", "buscgduus", "kzzltafhbzf", "ujyxkyxlzgsj"))
                .withTargetInfo(
                    new TargetRestoreInfo()
                        .withOverwriteOption(OverwriteOptions.OVERWRITE)
                        .withContainerId("bjlzqsczpgvdwn")
                        .withDatabaseName("fdqwowftpt")
                        .withTargetDirectoryForFileRestore("wjtkschgcgqyhl"))
                .withRecoveryMode(RecoveryMode.WORKLOAD_RECOVERY)
                .withTargetVirtualMachineId("q")
                .withShouldUseAlternateTargetLocation(false)
                .withIsNonRecoverable(false)
                .withAlternateDirectoryPaths(
                    Arrays
                        .asList(
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.LOG)
                                .withSourceLogicalName("kphyjdxrav")
                                .withSourcePath("qdbrxmrgc")
                                .withTargetPath("apx")))
                .withPointInTime(OffsetDateTime.parse("2021-08-13T07:45:29Z"))
                .withRecoveryPointRehydrationInfo(
                    new RecoveryPointRehydrationInfo()
                        .withRehydrationRetentionDuration("hychocokuleh")
                        .withRehydrationPriority(RehydrationPriority.HIGH));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadSqlPointInTimeRestoreWithRehydrateRequest.class);
        Assertions.assertEquals(RecoveryType.INVALID, model.recoveryType());
        Assertions.assertEquals("jjk", model.sourceResourceId());
        Assertions.assertEquals("buscgduus", model.propertyBag().get("oycblevpmc"));
        Assertions.assertEquals(OverwriteOptions.OVERWRITE, model.targetInfo().overwriteOption());
        Assertions.assertEquals("bjlzqsczpgvdwn", model.targetInfo().containerId());
        Assertions.assertEquals("fdqwowftpt", model.targetInfo().databaseName());
        Assertions.assertEquals("wjtkschgcgqyhl", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.WORKLOAD_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("q", model.targetVirtualMachineId());
        Assertions.assertEquals(false, model.shouldUseAlternateTargetLocation());
        Assertions.assertEquals(false, model.isNonRecoverable());
        Assertions.assertEquals(SqlDataDirectoryType.LOG, model.alternateDirectoryPaths().get(0).mappingType());
        Assertions.assertEquals("kphyjdxrav", model.alternateDirectoryPaths().get(0).sourceLogicalName());
        Assertions.assertEquals("qdbrxmrgc", model.alternateDirectoryPaths().get(0).sourcePath());
        Assertions.assertEquals("apx", model.alternateDirectoryPaths().get(0).targetPath());
        Assertions.assertEquals(OffsetDateTime.parse("2021-08-13T07:45:29Z"), model.pointInTime());
        Assertions.assertEquals("hychocokuleh", 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;
    }
}
