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

public final class AzureWorkloadSqlRestoreRequestTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        AzureWorkloadSqlRestoreRequest model =
            BinaryData
                .fromString(
                    "{\"objectType\":\"AzureWorkloadSQLRestoreRequest\",\"shouldUseAlternateTargetLocation\":false,\"isNonRecoverable\":false,\"alternateDirectoryPaths\":[{\"mappingType\":\"Invalid\",\"sourceLogicalName\":\"hohsd\",\"sourcePath\":\"cdzsu\",\"targetPath\":\"ohdxbzlmcmu\"},{\"mappingType\":\"Invalid\",\"sourceLogicalName\":\"hdbevwqqxeyskon\",\"sourcePath\":\"inkfkbgbz\",\"targetPath\":\"wxeqocljmygvkzqk\"}],\"recoveryType\":\"RestoreDisks\",\"sourceResourceId\":\"kbzefezrxcczurt\",\"propertyBag\":{\"zdix\":\"pqxbkwvzgnzvdf\",\"opqhewjptmc\":\"mqpnoda\",\"dlat\":\"sbostzel\",\"hrbbpneqvcwwyy\":\"tmzlbiojlv\"},\"targetInfo\":{\"overwriteOption\":\"Invalid\",\"containerId\":\"hppr\",\"databaseName\":\"snmokayzej\",\"targetDirectoryForFileRestore\":\"lbkpb\"},\"recoveryMode\":\"FileRecovery\",\"targetVirtualMachineId\":\"iljhahz\"}")
                .toObject(AzureWorkloadSqlRestoreRequest.class);
        Assertions.assertEquals(RecoveryType.RESTORE_DISKS, model.recoveryType());
        Assertions.assertEquals("kbzefezrxcczurt", model.sourceResourceId());
        Assertions.assertEquals("pqxbkwvzgnzvdf", model.propertyBag().get("zdix"));
        Assertions.assertEquals(OverwriteOptions.INVALID, model.targetInfo().overwriteOption());
        Assertions.assertEquals("hppr", model.targetInfo().containerId());
        Assertions.assertEquals("snmokayzej", model.targetInfo().databaseName());
        Assertions.assertEquals("lbkpb", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.FILE_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("iljhahz", model.targetVirtualMachineId());
        Assertions.assertEquals(false, model.shouldUseAlternateTargetLocation());
        Assertions.assertEquals(false, model.isNonRecoverable());
        Assertions.assertEquals(SqlDataDirectoryType.INVALID, model.alternateDirectoryPaths().get(0).mappingType());
        Assertions.assertEquals("hohsd", model.alternateDirectoryPaths().get(0).sourceLogicalName());
        Assertions.assertEquals("cdzsu", model.alternateDirectoryPaths().get(0).sourcePath());
        Assertions.assertEquals("ohdxbzlmcmu", model.alternateDirectoryPaths().get(0).targetPath());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        AzureWorkloadSqlRestoreRequest model =
            new AzureWorkloadSqlRestoreRequest()
                .withRecoveryType(RecoveryType.RESTORE_DISKS)
                .withSourceResourceId("kbzefezrxcczurt")
                .withPropertyBag(
                    mapOf(
                        "zdix",
                        "pqxbkwvzgnzvdf",
                        "opqhewjptmc",
                        "mqpnoda",
                        "dlat",
                        "sbostzel",
                        "hrbbpneqvcwwyy",
                        "tmzlbiojlv"))
                .withTargetInfo(
                    new TargetRestoreInfo()
                        .withOverwriteOption(OverwriteOptions.INVALID)
                        .withContainerId("hppr")
                        .withDatabaseName("snmokayzej")
                        .withTargetDirectoryForFileRestore("lbkpb"))
                .withRecoveryMode(RecoveryMode.FILE_RECOVERY)
                .withTargetVirtualMachineId("iljhahz")
                .withShouldUseAlternateTargetLocation(false)
                .withIsNonRecoverable(false)
                .withAlternateDirectoryPaths(
                    Arrays
                        .asList(
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.INVALID)
                                .withSourceLogicalName("hohsd")
                                .withSourcePath("cdzsu")
                                .withTargetPath("ohdxbzlmcmu"),
                            new SqlDataDirectoryMapping()
                                .withMappingType(SqlDataDirectoryType.INVALID)
                                .withSourceLogicalName("hdbevwqqxeyskon")
                                .withSourcePath("inkfkbgbz")
                                .withTargetPath("wxeqocljmygvkzqk")));
        model = BinaryData.fromObject(model).toObject(AzureWorkloadSqlRestoreRequest.class);
        Assertions.assertEquals(RecoveryType.RESTORE_DISKS, model.recoveryType());
        Assertions.assertEquals("kbzefezrxcczurt", model.sourceResourceId());
        Assertions.assertEquals("pqxbkwvzgnzvdf", model.propertyBag().get("zdix"));
        Assertions.assertEquals(OverwriteOptions.INVALID, model.targetInfo().overwriteOption());
        Assertions.assertEquals("hppr", model.targetInfo().containerId());
        Assertions.assertEquals("snmokayzej", model.targetInfo().databaseName());
        Assertions.assertEquals("lbkpb", model.targetInfo().targetDirectoryForFileRestore());
        Assertions.assertEquals(RecoveryMode.FILE_RECOVERY, model.recoveryMode());
        Assertions.assertEquals("iljhahz", model.targetVirtualMachineId());
        Assertions.assertEquals(false, model.shouldUseAlternateTargetLocation());
        Assertions.assertEquals(false, model.isNonRecoverable());
        Assertions.assertEquals(SqlDataDirectoryType.INVALID, model.alternateDirectoryPaths().get(0).mappingType());
        Assertions.assertEquals("hohsd", model.alternateDirectoryPaths().get(0).sourceLogicalName());
        Assertions.assertEquals("cdzsu", model.alternateDirectoryPaths().get(0).sourcePath());
        Assertions.assertEquals("ohdxbzlmcmu", model.alternateDirectoryPaths().get(0).targetPath());
    }

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