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

package com.azure.resourcemanager.recoveryservices.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.recoveryservices.models.IdentityData;
import com.azure.resourcemanager.recoveryservices.models.InfrastructureEncryptionState;
import com.azure.resourcemanager.recoveryservices.models.MonitoringSettings;
import com.azure.resourcemanager.recoveryservices.models.PatchVault;
import com.azure.resourcemanager.recoveryservices.models.PublicNetworkAccess;
import com.azure.resourcemanager.recoveryservices.models.ResourceIdentityType;
import com.azure.resourcemanager.recoveryservices.models.RestoreSettings;
import com.azure.resourcemanager.recoveryservices.models.SecuritySettings;
import com.azure.resourcemanager.recoveryservices.models.Sku;
import com.azure.resourcemanager.recoveryservices.models.SkuName;
import com.azure.resourcemanager.recoveryservices.models.UpgradeDetails;
import com.azure.resourcemanager.recoveryservices.models.UserIdentity;
import com.azure.resourcemanager.recoveryservices.models.VaultProperties;
import com.azure.resourcemanager.recoveryservices.models.VaultPropertiesEncryption;
import com.azure.resourcemanager.recoveryservices.models.VaultPropertiesMoveDetails;
import com.azure.resourcemanager.recoveryservices.models.VaultPropertiesRedundancySettings;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class PatchVaultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PatchVault model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"xjnspy\",\"upgradeDetails\":{\"operationId\":\"koen\",\"startTimeUtc\":\"2021-08-24T09:48:52Z\",\"lastUpdatedTimeUtc\":\"2021-04-14T04:43:28Z\",\"endTimeUtc\":\"2021-01-26T12:33:37Z\",\"status\":\"Upgraded\",\"message\":\"iukbldngkpoci\",\"triggerType\":\"UserTriggered\",\"upgradedResourceId\":\"xoegukgjnpiucgy\",\"previousResourceId\":\"vqzntypmrbpizcdr\"},\"privateEndpointConnections\":[{\"id\":\"pyd\",\"name\":\"hxdeoejz\",\"type\":\"w\",\"location\":\"sjttgzfbish\"},{\"id\":\"khaj\",\"name\":\"eamdp\",\"type\":\"g\",\"location\":\"pbuxwgipwhon\"},{\"id\":\"kgshwa\",\"name\":\"xzbinjeputt\",\"type\":\"ywnuzoq\",\"location\":\"iyqzrnk\"},{\"id\":\"vyxlwhzlsicohoqq\",\"name\":\"lryav\",\"type\":\"heun\",\"location\":\"qhgyxzkonocukok\"}],\"privateEndpointStateForBackup\":\"None\",\"privateEndpointStateForSiteRecovery\":\"Enabled\",\"encryption\":{\"infrastructureEncryption\":\"Enabled\"},\"moveDetails\":{\"operationId\":\"fkbey\",\"startTimeUtc\":\"2021-03-31T17:10:24Z\",\"completionTimeUtc\":\"2021-03-15T02:17:35Z\",\"sourceResourceId\":\"mwvvjektcxsenhw\",\"targetResourceId\":\"s\"},\"moveState\":\"CommitFailed\",\"backupStorageVersion\":\"V2\",\"publicNetworkAccess\":\"Enabled\",\"monitoringSettings\":{},\"restoreSettings\":{},\"redundancySettings\":{\"standardTierStorageRedundancy\":\"ZoneRedundant\",\"crossRegionRestore\":\"Disabled\"},\"securitySettings\":{}},\"sku\":{\"name\":\"RS0\",\"tier\":\"tcktvfcivfsnky\",\"family\":\"ctq\",\"size\":\"fbebrjcxer\",\"capacity\":\"wutttxfvjrbi\"},\"identity\":{\"principalId\":\"xepcyvahfn\",\"tenantId\":\"kyqxjvuujqgidokg\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{\"bijhtxfvgxbf\":{\"principalId\":\"xgvcl\",\"clientId\":\"gsncghkjeszz\"},\"gr\":{\"principalId\":\"xnehmpvec\",\"clientId\":\"odebfqkkrbmpu\"},\"qzahmgkbrp\":{\"principalId\":\"flz\",\"clientId\":\"bxzpuzycisp\"},\"gvtqagnbuynh\":{\"principalId\":\"dhibnuq\",\"clientId\":\"pikad\"}}},\"location\":\"gg\",\"tags\":{\"vpnazzm\":\"fsiarbutr\"},\"etag\":\"runmp\",\"id\":\"ttdbhrbnl\",\"name\":\"nkxmyskpbhenbtk\",\"type\":\"xywnytnrsynlqidy\"}")
                .toObject(PatchVault.class);
        Assertions.assertEquals("gg", model.location());
        Assertions.assertEquals("fsiarbutr", model.tags().get("vpnazzm"));
        Assertions.assertEquals("runmp", model.etag());
        Assertions
            .assertEquals(
                InfrastructureEncryptionState.ENABLED, model.properties().encryption().infrastructureEncryption());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.properties().publicNetworkAccess());
        Assertions.assertEquals(SkuName.RS0, model.sku().name());
        Assertions.assertEquals("tcktvfcivfsnky", model.sku().tier());
        Assertions.assertEquals("ctq", model.sku().family());
        Assertions.assertEquals("fbebrjcxer", model.sku().size());
        Assertions.assertEquals("wutttxfvjrbi", model.sku().capacity());
        Assertions.assertEquals(ResourceIdentityType.USER_ASSIGNED, model.identity().type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PatchVault model =
            new PatchVault()
                .withLocation("gg")
                .withTags(mapOf("vpnazzm", "fsiarbutr"))
                .withEtag("runmp")
                .withProperties(
                    new VaultProperties()
                        .withUpgradeDetails(new UpgradeDetails())
                        .withEncryption(
                            new VaultPropertiesEncryption()
                                .withInfrastructureEncryption(InfrastructureEncryptionState.ENABLED))
                        .withMoveDetails(new VaultPropertiesMoveDetails())
                        .withPublicNetworkAccess(PublicNetworkAccess.ENABLED)
                        .withMonitoringSettings(new MonitoringSettings())
                        .withRestoreSettings(new RestoreSettings())
                        .withRedundancySettings(new VaultPropertiesRedundancySettings())
                        .withSecuritySettings(new SecuritySettings()))
                .withSku(
                    new Sku()
                        .withName(SkuName.RS0)
                        .withTier("tcktvfcivfsnky")
                        .withFamily("ctq")
                        .withSize("fbebrjcxer")
                        .withCapacity("wutttxfvjrbi"))
                .withIdentity(
                    new IdentityData()
                        .withType(ResourceIdentityType.USER_ASSIGNED)
                        .withUserAssignedIdentities(
                            mapOf(
                                "bijhtxfvgxbf",
                                new UserIdentity(),
                                "gr",
                                new UserIdentity(),
                                "qzahmgkbrp",
                                new UserIdentity(),
                                "gvtqagnbuynh",
                                new UserIdentity())));
        model = BinaryData.fromObject(model).toObject(PatchVault.class);
        Assertions.assertEquals("gg", model.location());
        Assertions.assertEquals("fsiarbutr", model.tags().get("vpnazzm"));
        Assertions.assertEquals("runmp", model.etag());
        Assertions
            .assertEquals(
                InfrastructureEncryptionState.ENABLED, model.properties().encryption().infrastructureEncryption());
        Assertions.assertEquals(PublicNetworkAccess.ENABLED, model.properties().publicNetworkAccess());
        Assertions.assertEquals(SkuName.RS0, model.sku().name());
        Assertions.assertEquals("tcktvfcivfsnky", model.sku().tier());
        Assertions.assertEquals("ctq", model.sku().family());
        Assertions.assertEquals("fbebrjcxer", model.sku().size());
        Assertions.assertEquals("wutttxfvjrbi", model.sku().capacity());
        Assertions.assertEquals(ResourceIdentityType.USER_ASSIGNED, model.identity().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;
    }
}
