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

package com.azure.resourcemanager.devtestlabs.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.devtestlabs.fluent.models.ArtifactInner;
import com.azure.resourcemanager.devtestlabs.models.ArtifactList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class ArtifactListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        ArtifactList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"title\":\"mtxpsiebtfh\",\"description\":\"esap\",\"publisher\":\"rdqmhjjdhtldwkyz\",\"filePath\":\"utknc\",\"icon\":\"cwsvlxotog\",\"targetOsType\":\"rupqsxvnmicy\",\"parameters\":\"dataceoveilovno\",\"createdDate\":\"2021-10-13T06:15:30Z\"},\"location\":\"jfcn\",\"tags\":{\"dhbt\":\"cn\"},\"id\":\"kphywpnvjto\",\"name\":\"nermcl\",\"type\":\"plpho\"},{\"properties\":{\"title\":\"scrpabgyepsbjt\",\"description\":\"qugxywpmueefjzwf\",\"publisher\":\"q\",\"filePath\":\"ids\",\"icon\":\"onobglaocqx\",\"targetOsType\":\"cmgyud\",\"parameters\":\"datatlmoyrx\",\"createdDate\":\"2021-08-04T10:24:08Z\"},\"location\":\"u\",\"tags\":{\"lrqjbhckfr\":\"zntxhdz\"},\"id\":\"hrxsbk\",\"name\":\"vpycanuzbp\",\"type\":\"kafkuwbcrnwbm\"},{\"properties\":{\"title\":\"hseyvju\",\"description\":\"tslhspkdeem\",\"publisher\":\"fm\",\"filePath\":\"gkvtmelmqkrhah\",\"icon\":\"juahaquhcdhmdual\",\"targetOsType\":\"xqpvfadmw\",\"parameters\":\"datacrgvxpvgom\",\"createdDate\":\"2021-03-14T19:51:15Z\"},\"location\":\"misgwbnb\",\"tags\":{\"urqhaka\":\"dawkzbali\",\"xcug\":\"hashsfwxosow\",\"ovbvmeueciv\":\"cjooxdjebwpucwwf\",\"otwmcdyt\":\"hzceuojgjrwjue\"},\"id\":\"x\",\"name\":\"it\",\"type\":\"nrjawgqwg\"},{\"properties\":{\"title\":\"ni\",\"description\":\"x\",\"publisher\":\"kpycgklwndnhjd\",\"filePath\":\"whvylw\",\"icon\":\"tdhxujznbmpowuwp\",\"targetOsType\":\"qlveualupjmkh\",\"parameters\":\"dataobbc\",\"createdDate\":\"2021-03-12T03:03:28Z\"},\"location\":\"rtjriplrbpbew\",\"tags\":{\"c\":\"fgb\",\"gibtnm\":\"wxzvlvqhjkb\"},\"id\":\"iebwwaloayqcgwrt\",\"name\":\"j\",\"type\":\"zg\"}],\"nextLink\":\"zmh\"}")
                .toObject(ArtifactList.class);
        Assertions.assertEquals("jfcn", model.value().get(0).location());
        Assertions.assertEquals("cn", model.value().get(0).tags().get("dhbt"));
        Assertions.assertEquals("zmh", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        ArtifactList model =
            new ArtifactList()
                .withValue(
                    Arrays
                        .asList(
                            new ArtifactInner().withLocation("jfcn").withTags(mapOf("dhbt", "cn")),
                            new ArtifactInner().withLocation("u").withTags(mapOf("lrqjbhckfr", "zntxhdz")),
                            new ArtifactInner()
                                .withLocation("misgwbnb")
                                .withTags(
                                    mapOf(
                                        "urqhaka",
                                        "dawkzbali",
                                        "xcug",
                                        "hashsfwxosow",
                                        "ovbvmeueciv",
                                        "cjooxdjebwpucwwf",
                                        "otwmcdyt",
                                        "hzceuojgjrwjue")),
                            new ArtifactInner()
                                .withLocation("rtjriplrbpbew")
                                .withTags(mapOf("c", "fgb", "gibtnm", "wxzvlvqhjkb"))))
                .withNextLink("zmh");
        model = BinaryData.fromObject(model).toObject(ArtifactList.class);
        Assertions.assertEquals("jfcn", model.value().get(0).location());
        Assertions.assertEquals("cn", model.value().get(0).tags().get("dhbt"));
        Assertions.assertEquals("zmh", model.nextLink());
    }

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