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

package com.azure.resourcemanager.costmanagement.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.costmanagement.fluent.models.QueryResultInner;
import com.azure.resourcemanager.costmanagement.models.QueryColumn;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class QueryResultInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        QueryResultInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"nextLink\":\"synljphuopxodl\",\"columns\":[{\"name\":\"torzih\",\"type\":\"osjswsr\"}],\"rows\":[[\"datazrpzb\",\"datahckqqzqioxiy\",\"datauiizynke\",\"datayatrwy\"],[\"datamibzyhwitsmypyyn\"],[\"datadpumnzgmw\"],[\"datamabiknsorgjhxb\",\"datadtlwwrlkd\"]]},\"sku\":\"ncvokotllxdyhg\",\"eTag\":\"ocogj\",\"location\":\"tdtbnnhadooc\",\"tags\":{\"amqgxqquezikyw\":\"cikhnv\",\"lla\":\"gxk\",\"z\":\"melwuipiccjz\",\"vvcnayr\":\"v\"},\"id\":\"yrnxxmueedn\",\"name\":\"rdvstkwqqtch\",\"type\":\"alm\"}")
                .toObject(QueryResultInner.class);
        Assertions.assertEquals("tdtbnnhadooc", model.location());
        Assertions.assertEquals("cikhnv", model.tags().get("amqgxqquezikyw"));
        Assertions.assertEquals("synljphuopxodl", model.nextLink());
        Assertions.assertEquals("torzih", model.columns().get(0).name());
        Assertions.assertEquals("osjswsr", model.columns().get(0).type());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        QueryResultInner model =
            new QueryResultInner()
                .withLocation("tdtbnnhadooc")
                .withTags(mapOf("amqgxqquezikyw", "cikhnv", "lla", "gxk", "z", "melwuipiccjz", "vvcnayr", "v"))
                .withNextLink("synljphuopxodl")
                .withColumns(Arrays.asList(new QueryColumn().withName("torzih").withType("osjswsr")))
                .withRows(
                    Arrays
                        .asList(
                            Arrays.asList("datazrpzb", "datahckqqzqioxiy", "datauiizynke", "datayatrwy"),
                            Arrays.asList("datamibzyhwitsmypyyn"),
                            Arrays.asList("datadpumnzgmw"),
                            Arrays.asList("datamabiknsorgjhxb", "datadtlwwrlkd")));
        model = BinaryData.fromObject(model).toObject(QueryResultInner.class);
        Assertions.assertEquals("tdtbnnhadooc", model.location());
        Assertions.assertEquals("cikhnv", model.tags().get("amqgxqquezikyw"));
        Assertions.assertEquals("synljphuopxodl", model.nextLink());
        Assertions.assertEquals("torzih", model.columns().get(0).name());
        Assertions.assertEquals("osjswsr", model.columns().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;
    }
}
