// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.dataprotection.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.dataprotection.fluent.models.BackupVaultResourceInner;
import com.azure.resourcemanager.dataprotection.models.BackupVault;
import com.azure.resourcemanager.dataprotection.models.DppIdentityDetails;
import com.azure.resourcemanager.dataprotection.models.FeatureSettings;
import com.azure.resourcemanager.dataprotection.models.MonitoringSettings;
import com.azure.resourcemanager.dataprotection.models.SecuritySettings;
import com.azure.resourcemanager.dataprotection.models.StorageSetting;
import com.azure.resourcemanager.dataprotection.models.StorageSettingStoreTypes;
import com.azure.resourcemanager.dataprotection.models.StorageSettingTypes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class BackupVaultResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        BackupVaultResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"monitoringSettings\":{},\"provisioningState\":\"Provisioning\",\"resourceMoveState\":\"CriticalFailure\",\"resourceMoveDetails\":{\"operationId\":\"vd\",\"startTimeUtc\":\"jgrtfwvukxga\",\"completionTimeUtc\":\"ccsnhsjc\",\"sourceResourcePath\":\"ejhkry\",\"targetResourcePath\":\"napczwlokjy\"},\"securitySettings\":{},\"storageSettings\":[{\"datastoreType\":\"ArchiveStore\",\"type\":\"ZoneRedundant\"},{\"datastoreType\":\"VaultStore\",\"type\":\"ZoneRedundant\"}],\"isVaultProtectedByResourceGuard\":true,\"featureSettings\":{}},\"identity\":{\"principalId\":\"spodmail\",\"tenantId\":\"deh\",\"type\":\"wyahuxinpmqnja\"},\"eTag\":\"ixjsprozvcputeg\",\"location\":\"wmfdatscmdvpjhul\",\"tags\":{\"slwejdpvw\":\"vmkjozkrwfndiodj\"},\"id\":\"yoqpsoaccta\",\"name\":\"akl\",\"type\":\"lahbcryff\"}")
                .toObject(BackupVaultResourceInner.class);
        Assertions.assertEquals("wmfdatscmdvpjhul", model.location());
        Assertions.assertEquals("vmkjozkrwfndiodj", model.tags().get("slwejdpvw"));
        Assertions.assertEquals("ixjsprozvcputeg", model.etag());
        Assertions.assertEquals("wyahuxinpmqnja", model.identity().type());
        Assertions
            .assertEquals(
                StorageSettingStoreTypes.ARCHIVE_STORE, model.properties().storageSettings().get(0).datastoreType());
        Assertions.assertEquals(StorageSettingTypes.ZONE_REDUNDANT, model.properties().storageSettings().get(0).type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        BackupVaultResourceInner model =
            new BackupVaultResourceInner()
                .withLocation("wmfdatscmdvpjhul")
                .withTags(mapOf("slwejdpvw", "vmkjozkrwfndiodj"))
                .withEtag("ixjsprozvcputeg")
                .withIdentity(new DppIdentityDetails().withType("wyahuxinpmqnja"))
                .withProperties(
                    new BackupVault()
                        .withMonitoringSettings(new MonitoringSettings())
                        .withSecuritySettings(new SecuritySettings())
                        .withStorageSettings(
                            Arrays
                                .asList(
                                    new StorageSetting()
                                        .withDatastoreType(StorageSettingStoreTypes.ARCHIVE_STORE)
                                        .withType(StorageSettingTypes.ZONE_REDUNDANT),
                                    new StorageSetting()
                                        .withDatastoreType(StorageSettingStoreTypes.VAULT_STORE)
                                        .withType(StorageSettingTypes.ZONE_REDUNDANT)))
                        .withFeatureSettings(new FeatureSettings()));
        model = BinaryData.fromObject(model).toObject(BackupVaultResourceInner.class);
        Assertions.assertEquals("wmfdatscmdvpjhul", model.location());
        Assertions.assertEquals("vmkjozkrwfndiodj", model.tags().get("slwejdpvw"));
        Assertions.assertEquals("ixjsprozvcputeg", model.etag());
        Assertions.assertEquals("wyahuxinpmqnja", model.identity().type());
        Assertions
            .assertEquals(
                StorageSettingStoreTypes.ARCHIVE_STORE, model.properties().storageSettings().get(0).datastoreType());
        Assertions.assertEquals(StorageSettingTypes.ZONE_REDUNDANT, model.properties().storageSettings().get(0).type());
    }

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