// 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.AzureWorkloadSqlRestoreWithRehydrateRequest;
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.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class AzureWorkloadSqlRestoreWithRehydrateRequestTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadSqlRestoreWithRehydrateRequest model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadSQLRestoreWithRehydrateRequest\",\"recoveryPointRehydrationInfo\":{\"rehydrationRetentionDuration\":\"y\",\"rehydrationPriority\":\"Standard\"},\"shouldUseAlternateTargetLocation\":false,\"isNonRecoverable\":false,\"alternateDirectoryPaths\":[{\"mappingType\":\"Data\",\"sourceLogicalName\":\"ws\",\"sourcePath\":\"kjtasb\",\"targetPath\":\"ispkxkdtx\"},{\"mappingType\":\"Invalid\",\"sourceLogicalName\":\"lq\",\"sourcePath\":\"w\",\"targetPath\":\"vgmmbugtyw\"},{\"mappingType\":\"Log\",\"sourceLogicalName\":\"aqkue\",\"sourcePath\":\"groeshoyg\",\"targetPath\":\"byfqxkfaoy\"},{\"mappingType\":\"Log\",\"sourceLogicalName\":\"puvjmvqmtd\",\"sourcePath\":\"kygroejnndljdj\",\"targetPath\":\"kb\"}],\"recoveryType\":\"Invalid\",\"sourceResourceId\":\"ynkceysfaqegpl\",\"propertyBag\":{\"usybwptdaca\":\"shwddkvbxgk\"},\"targetInfo\":{\"overwriteOption\":\"FailOnConflict\",\"containerId\":\"ntymtpoiwenazero\",\"databaseName\":\"rs\",\"targetDirectoryForFileRestore\":\"lsxkd\"},\"recoveryMode\":\"Invalid\",\"targetVirtualMachineId\":\"pfgsdpcvessmzhh\"}")
                .toObject(AzureWorkloadSqlRestoreWithRehydrateRequest.class);
        Assertions.assertEquals(RecoveryType.INVALID, model.recoveryType());
        Assertions.assertEquals("ynkceysfaqegpl", model.sourceResourceId());
        Assertions.assertEquals("shwddkvbxgk", model.propertyBag().get("usybwptdaca"));
        Assertions.assertEquals(OverwriteOptions.FAIL_ON_CONFLICT, model.targetInfo().overwriteOption());
        Assertions.assertEquals("ntymtpoiwenazero", model.targetInfo().containerId());
        Assertions.assertEquals("rs", model.targetInfo().databaseName());
        Assertions.assertEquals("lsxkd", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.INVALID, model.recoveryMode());
        Assertions.assertEquals("pfgsdpcvessmzhh", model.targetVirtualMachineId());
        Assertions.assertEquals(false, model.shouldUseAlternateTargetLocation());
        Assertions.assertEquals(false, model.isNonRecoverable());
        Assertions.assertEquals(SqlDataDirectoryType.DATA, model.alternateDirectoryPaths().get(0).mappingType());
        Assertions.assertEquals("ws", model.alternateDirectoryPaths().get(0).sourceLogicalName());
        Assertions.assertEquals("kjtasb", model.alternateDirectoryPaths().get(0).sourcePath());
        Assertions.assertEquals("ispkxkdtx", model.alternateDirectoryPaths().get(0).targetPath());
        Assertions.assertEquals("y", model.recoveryPointRehydrationInfo().rehydrationRetentionDuration());
        Assertions
            .assertEquals(RehydrationPriority.STANDARD, model.recoveryPointRehydrationInfo().rehydrationPriority());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadSqlRestoreWithRehydrateRequest model =
            new AzureWorkloadSqlRestoreWithRehydrateRequest()
                .withRecoveryType(RecoveryType.INVALID)
                .withSourceResourceId("ynkceysfaqegpl")
                .withPropertyBag(mapOf("usybwptdaca", "shwddkvbxgk"))
                .withTargetInfo(
                    new TargetRestoreInfo()
                        .withOverwriteOption(OverwriteOptions.FAIL_ON_CONFLICT)
                        .withContainerId("ntymtpoiwenazero")
                        .withDatabaseName("rs")
                        .withTargetDirectoryForFileRestore("lsxkd"))
                .withRecoveryMode(RecoveryMode.INVALID)
                .withTargetVirtualMachineId("pfgsdpcvessmzhh")
                .withShouldUseAlternateTargetLocation(false)
                .withIsNonRecoverable(false)
                .withAlternateDirectoryPaths(
                    Arrays
                        .asList(
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.DATA)
                                .withSourceLogicalName("ws")
                                .withSourcePath("kjtasb")
                                .withTargetPath("ispkxkdtx"),
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.INVALID)
                                .withSourceLogicalName("lq")
                                .withSourcePath("w")
                                .withTargetPath("vgmmbugtyw"),
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.LOG)
                                .withSourceLogicalName("aqkue")
                                .withSourcePath("groeshoyg")
                                .withTargetPath("byfqxkfaoy"),
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.LOG)
                                .withSourceLogicalName("puvjmvqmtd")
                                .withSourcePath("kygroejnndljdj")
                                .withTargetPath("kb")))
                .withRecoveryPointRehydrationInfo(
                    new RecoveryPointRehydrationInfo()
                        .withRehydrationRetentionDuration("y")
                        .withRehydrationPriority(RehydrationPriority.STANDARD));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadSqlRestoreWithRehydrateRequest.class);
        Assertions.assertEquals(RecoveryType.INVALID, model.recoveryType());
        Assertions.assertEquals("ynkceysfaqegpl", model.sourceResourceId());
        Assertions.assertEquals("shwddkvbxgk", model.propertyBag().get("usybwptdaca"));
        Assertions.assertEquals(OverwriteOptions.FAIL_ON_CONFLICT, model.targetInfo().overwriteOption());
        Assertions.assertEquals("ntymtpoiwenazero", model.targetInfo().containerId());
        Assertions.assertEquals("rs", model.targetInfo().databaseName());
        Assertions.assertEquals("lsxkd", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.INVALID, model.recoveryMode());
        Assertions.assertEquals("pfgsdpcvessmzhh", model.targetVirtualMachineId());
        Assertions.assertEquals(false, model.shouldUseAlternateTargetLocation());
        Assertions.assertEquals(false, model.isNonRecoverable());
        Assertions.assertEquals(SqlDataDirectoryType.DATA, model.alternateDirectoryPaths().get(0).mappingType());
        Assertions.assertEquals("ws", model.alternateDirectoryPaths().get(0).sourceLogicalName());
        Assertions.assertEquals("kjtasb", model.alternateDirectoryPaths().get(0).sourcePath());
        Assertions.assertEquals("ispkxkdtx", model.alternateDirectoryPaths().get(0).targetPath());
        Assertions.assertEquals("y", model.recoveryPointRehydrationInfo().rehydrationRetentionDuration());
        Assertions
            .assertEquals(RehydrationPriority.STANDARD, 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;
    }
}
