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

package com.azure.resourcemanager.azurearcdata.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.azurearcdata.fluent.models.DataControllerResourceInner;
import com.azure.resourcemanager.azurearcdata.models.DataControllerProperties;
import com.azure.resourcemanager.azurearcdata.models.ExtendedLocation;
import com.azure.resourcemanager.azurearcdata.models.ExtendedLocationTypes;
import com.azure.resourcemanager.azurearcdata.models.Infrastructure;
import com.azure.resourcemanager.azurearcdata.models.PageOfDataControllerResource;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class PageOfDataControllerResourceTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PageOfDataControllerResource model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"extendedLocation\":{\"name\":\"cq\",\"type\":\"CustomLocation\"},\"properties\":{\"infrastructure\":\"azure\",\"k8sRaw\":\"dataudxytlmoyrx\",\"lastUploadedDate\":\"2021-03-16T12:34:31Z\",\"provisioningState\":\"ntxhdzhlrqjbhck\",\"clusterId\":\"lhrxsbkyvpyc\",\"extensionId\":\"uzbpzkafku\"},\"location\":\"crnwbmeh\",\"tags\":{\"deemao\":\"yvjusrtslhsp\",\"gkvtmelmqkrhah\":\"mx\",\"duala\":\"ljuahaquhcdh\",\"rcrgvx\":\"xqpvfadmw\"},\"id\":\"vgomz\",\"name\":\"fmisg\",\"type\":\"bnbbeldawkz\"},{\"extendedLocation\":{\"name\":\"io\",\"type\":\"CustomLocation\"},\"properties\":{\"infrastructure\":\"alibaba\",\"k8sRaw\":\"datauhashsfwx\",\"lastUploadedDate\":\"2021-11-02T12:01:24Z\",\"provisioningState\":\"gicjooxdjeb\",\"clusterId\":\"ucww\",\"extensionId\":\"ovbvmeueciv\"},\"location\":\"zceuojgjrw\",\"tags\":{\"nrjawgqwg\":\"iotwmcdytdxwit\",\"klwndnhjdauwhv\":\"hniskxfbkpyc\",\"zbtd\":\"l\"},\"id\":\"xujznbmpowu\",\"name\":\"przqlveu\",\"type\":\"lupj\"},{\"extendedLocation\":{\"name\":\"fxobbcsws\",\"type\":\"CustomLocation\"},\"properties\":{\"infrastructure\":\"alibaba\",\"k8sRaw\":\"datarbpbewtghfgblcg\",\"lastUploadedDate\":\"2021-01-14T04:37:45Z\",\"provisioningState\":\"jkbegibtnmxiebww\",\"clusterId\":\"oayqc\",\"extensionId\":\"rtzju\"},\"location\":\"wyzmhtxon\",\"tags\":{\"knftguvriuh\":\"savjcbpwxqps\"},\"id\":\"rwmdyvxqtay\",\"name\":\"iwwroyqbexrmc\",\"type\":\"ibycno\"}],\"nextLink\":\"knme\"}")
                .toObject(PageOfDataControllerResource.class);
        Assertions.assertEquals("crnwbmeh", model.value().get(0).location());
        Assertions.assertEquals("yvjusrtslhsp", model.value().get(0).tags().get("deemao"));
        Assertions.assertEquals("cq", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals(ExtendedLocationTypes.CUSTOM_LOCATION, model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(Infrastructure.AZURE, model.value().get(0).properties().infrastructure());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-03-16T12:34:31Z"), model.value().get(0).properties().lastUploadedDate());
        Assertions.assertEquals("lhrxsbkyvpyc", model.value().get(0).properties().clusterId());
        Assertions.assertEquals("uzbpzkafku", model.value().get(0).properties().extensionId());
        Assertions.assertEquals("knme", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PageOfDataControllerResource model =
            new PageOfDataControllerResource()
                .withValue(
                    Arrays
                        .asList(
                            new DataControllerResourceInner()
                                .withLocation("crnwbmeh")
                                .withTags(
                                    mapOf(
                                        "deemao",
                                        "yvjusrtslhsp",
                                        "gkvtmelmqkrhah",
                                        "mx",
                                        "duala",
                                        "ljuahaquhcdh",
                                        "rcrgvx",
                                        "xqpvfadmw"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("cq")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withProperties(
                                    new DataControllerProperties()
                                        .withInfrastructure(Infrastructure.AZURE)
                                        .withK8SRaw("dataudxytlmoyrx")
                                        .withLastUploadedDate(OffsetDateTime.parse("2021-03-16T12:34:31Z"))
                                        .withClusterId("lhrxsbkyvpyc")
                                        .withExtensionId("uzbpzkafku")),
                            new DataControllerResourceInner()
                                .withLocation("zceuojgjrw")
                                .withTags(
                                    mapOf("nrjawgqwg", "iotwmcdytdxwit", "klwndnhjdauwhv", "hniskxfbkpyc", "zbtd", "l"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("io")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withProperties(
                                    new DataControllerProperties()
                                        .withInfrastructure(Infrastructure.ALIBABA)
                                        .withK8SRaw("datauhashsfwx")
                                        .withLastUploadedDate(OffsetDateTime.parse("2021-11-02T12:01:24Z"))
                                        .withClusterId("ucww")
                                        .withExtensionId("ovbvmeueciv")),
                            new DataControllerResourceInner()
                                .withLocation("wyzmhtxon")
                                .withTags(mapOf("knftguvriuh", "savjcbpwxqps"))
                                .withExtendedLocation(
                                    new ExtendedLocation()
                                        .withName("fxobbcsws")
                                        .withType(ExtendedLocationTypes.CUSTOM_LOCATION))
                                .withProperties(
                                    new DataControllerProperties()
                                        .withInfrastructure(Infrastructure.ALIBABA)
                                        .withK8SRaw("datarbpbewtghfgblcg")
                                        .withLastUploadedDate(OffsetDateTime.parse("2021-01-14T04:37:45Z"))
                                        .withClusterId("oayqc")
                                        .withExtensionId("rtzju"))))
                .withNextLink("knme");
        model = BinaryData.fromObject(model).toObject(PageOfDataControllerResource.class);
        Assertions.assertEquals("crnwbmeh", model.value().get(0).location());
        Assertions.assertEquals("yvjusrtslhsp", model.value().get(0).tags().get("deemao"));
        Assertions.assertEquals("cq", model.value().get(0).extendedLocation().name());
        Assertions.assertEquals(ExtendedLocationTypes.CUSTOM_LOCATION, model.value().get(0).extendedLocation().type());
        Assertions.assertEquals(Infrastructure.AZURE, model.value().get(0).properties().infrastructure());
        Assertions
            .assertEquals(
                OffsetDateTime.parse("2021-03-16T12:34:31Z"), model.value().get(0).properties().lastUploadedDate());
        Assertions.assertEquals("lhrxsbkyvpyc", model.value().get(0).properties().clusterId());
        Assertions.assertEquals("uzbpzkafku", model.value().get(0).properties().extensionId());
        Assertions.assertEquals("knme", 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;
    }
}
