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

package com.azure.resourcemanager.elasticsan.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.elasticsan.models.EncryptionType;
import com.azure.resourcemanager.elasticsan.models.NetworkRuleSet;
import com.azure.resourcemanager.elasticsan.models.StorageTargetType;
import com.azure.resourcemanager.elasticsan.models.VolumeGroupUpdate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public final class VolumeGroupUpdateTests {
    @Test
    public void testDeserialize() {
        VolumeGroupUpdate model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"protocolType\":\"None\",\"encryption\":\"EncryptionAtRestWithPlatformKey\",\"networkAcls\":{\"virtualNetworkRules\":[]}},\"tags\":{\"a\":\"w\"}}")
                .toObject(VolumeGroupUpdate.class);
        Assertions.assertEquals("w", model.tags().get("a"));
        Assertions.assertEquals(StorageTargetType.NONE, model.protocolType());
        Assertions.assertEquals(EncryptionType.ENCRYPTION_AT_REST_WITH_PLATFORM_KEY, model.encryption());
    }

    @Test
    public void testSerialize() {
        VolumeGroupUpdate model =
            new VolumeGroupUpdate()
                .withTags(mapOf("a", "w"))
                .withProtocolType(StorageTargetType.NONE)
                .withEncryption(EncryptionType.ENCRYPTION_AT_REST_WITH_PLATFORM_KEY)
                .withNetworkAcls(new NetworkRuleSet().withVirtualNetworkRules(Arrays.asList()));
        model = BinaryData.fromObject(model).toObject(VolumeGroupUpdate.class);
        Assertions.assertEquals("w", model.tags().get("a"));
        Assertions.assertEquals(StorageTargetType.NONE, model.protocolType());
        Assertions.assertEquals(EncryptionType.ENCRYPTION_AT_REST_WITH_PLATFORM_KEY, model.encryption());
    }

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