// 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\":\"mpimaqxzhemjyh\",\"value\":[{\"extendedLocation\":{\"name\":\"jswtwkozzwc\",\"type\":\"lkb\"},\"properties\":{\"attachedTo\":[],\"detailedStatus\":\"Active\",\"detailedStatusMessage\":\"jnjwltlwt\",\"provisioningState\":\"Accepted\",\"serialNumber\":\"ktalhsnvkcdmxz\",\"sizeMiB\":7215202878981332083},\"location\":\"imlnwiaaomylw\",\"tags\":{\"l\":\"ulcsethwwnpj\"},\"id\":\"zswpchwa\",\"name\":\"fb\",\"type\":\"usnfepgfewet\"}]}")
                .toObject(VolumeList.class);
        Assertions.assertEquals("mpimaqxzhemjyh", model.nextLink());
        Assertions.assertEquals("imlnwiaaomylw", model.value().get(0).location());
        Assertions.assertEquals("ulcsethwwnpj", model.value().get(0).tags().get("l"));
        Assertions.assertEquals("jswtwkozzwc", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("lkb", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(7215202878981332083L, model.value().get(0).sizeMiB());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        VolumeList model =
            new VolumeList()
                .withNextLink("mpimaqxzhemjyh")
                .withValue(
                    Arrays
                        .asList(
                            new VolumeInner()
                                .withLocation("imlnwiaaomylw")
                                .withTags(mapOf("l", "ulcsethwwnpj"))
                                .withExtendedLocation(new ExtendedLocation().withName("jswtwkozzwc").withType("lkb"))
                                .withSizeMiB(7215202878981332083L)));
        model = BinaryData.fromObject(model).toObject(VolumeList.class);
        Assertions.assertEquals("mpimaqxzhemjyh", model.nextLink());
        Assertions.assertEquals("imlnwiaaomylw", model.value().get(0).location());
        Assertions.assertEquals("ulcsethwwnpj", model.value().get(0).tags().get("l"));
        Assertions.assertEquals("jswtwkozzwc", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals("lkb", model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(7215202878981332083L, model.value().get(0).sizeMiB());
    }

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