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

package com.azure.resourcemanager.networkcloud.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.networkcloud.fluent.models.VolumeInner;
import com.azure.resourcemanager.networkcloud.models.ExtendedLocation;
import com.azure.resourcemanager.networkcloud.models.VolumeList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class VolumeListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        VolumeList model =
            BinaryData
                .fromString(
                    "{\"nextLink\":\"hcmavmqfo\",\"value\":[{\"extendedLocation\":{\"name\":\"rhc\",\"type\":\"yyprotwyp\"},\"properties\":{\"attachedTo\":[\"mbxhugcmjkav\"],\"detailedStatus\":\"Error\",\"detailedStatusMessage\":\"bmftpmdt\",\"provisioningState\":\"Succeeded\",\"serialNumber\":\"tfvnz\",\"sizeMiB\":1221267442521821688},\"location\":\"otp\",\"tags\":{\"ihed\":\"vpbdbzqgq\",\"mkyi\":\"vqwt\",\"qcwdhoh\":\"cysihs\",\"sufco\":\"dtmcd\"},\"id\":\"dxbzlmcmuap\",\"name\":\"vhdbevwqqxey\",\"type\":\"ko\"}]}")
                .toObject(VolumeList.class);
        Assertions.assertEquals("hcmavmqfo", model.nextLink());
        Assertions.assertEquals("otp", model.value().get(0).location());
        Assertions.assertEquals("vpbdbzqgq", model.value().get(0).tags().get("ihed"));
        Assertions.assertEquals("rhc", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("yyprotwyp", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(1221267442521821688L, model.value().get(0).sizeMiB());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        VolumeList model =
            new VolumeList()
                .withNextLink("hcmavmqfo")
                .withValue(
                    Arrays
                        .asList(
                            new VolumeInner()
                                .withLocation("otp")
                                .withTags(
                                    mapOf("ihed", "vpbdbzqgq", "mkyi", "vqwt", "qcwdhoh", "cysihs", "sufco", "dtmcd"))
                                .withExtendedLocation(new ExtendedLocation().withName("rhc").withType("yyprotwyp"))
                                .withSizeMiB(1221267442521821688L)));
        model = BinaryData.fromObject(model).toObject(VolumeList.class);
        Assertions.assertEquals("hcmavmqfo", model.nextLink());
        Assertions.assertEquals("otp", model.value().get(0).location());
        Assertions.assertEquals("vpbdbzqgq", model.value().get(0).tags().get("ihed"));
        Assertions.assertEquals("rhc", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("yyprotwyp", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(1221267442521821688L, model.value().get(0).sizeMiB());
    }

    // Use "Map.of" if available
    @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;
    }
}
