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

package com.azure.resourcemanager.communication.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.communication.fluent.models.CommunicationServiceResourceInner;
import com.azure.resourcemanager.communication.models.CommunicationServiceResourceList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class CommunicationServiceResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        CommunicationServiceResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"provisioningState\":\"Running\",\"hostName\":\"mkkvnip\",\"dataLocation\":\"oxzjnchgejspod\",\"notificationHubId\":\"ilzyd\",\"version\":\"o\",\"immutableResourceId\":\"yahux\",\"linkedDomains\":[]},\"location\":\"mqnjaqw\",\"tags\":{\"gjvw\":\"sprozvcput\",\"dvpjhulsuuvmk\":\"fdatsc\",\"jdpvwryo\":\"ozkrwfndiodjpslw\"},\"id\":\"psoacctazakljl\",\"name\":\"hbcryffdfdosyge\",\"type\":\"paojakhmsbzjh\"},{\"properties\":{\"provisioningState\":\"Canceled\",\"hostName\":\"dphlxaolt\",\"dataLocation\":\"qtrgqjbpfzfsinzg\",\"notificationHubId\":\"cjrwzoxxjtfellu\",\"version\":\"zitonpeqfpjkjl\",\"immutableResourceId\":\"fpdvhpfxxypi\",\"linkedDomains\":[]},\"location\":\"mayhuybbkpodepoo\",\"tags\":{\"eotusivyevc\":\"uvamiheognarxzxt\",\"un\":\"iqihn\",\"fygxgispemvtzfk\":\"bwjzr\"},\"id\":\"fublj\",\"name\":\"fxqeof\",\"type\":\"aeqjhqjbasvms\"}],\"nextLink\":\"qulngsntnbybkzgc\"}")
                .toObject(CommunicationServiceResourceList.class);
        Assertions.assertEquals("mqnjaqw", model.value().get(0).location());
        Assertions.assertEquals("sprozvcput", model.value().get(0).tags().get("gjvw"));
        Assertions.assertEquals("oxzjnchgejspod", model.value().get(0).dataLocation());
        Assertions.assertEquals("qulngsntnbybkzgc", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        CommunicationServiceResourceList model =
            new CommunicationServiceResourceList()
                .withValue(
                    Arrays
                        .asList(
                            new CommunicationServiceResourceInner()
                                .withLocation("mqnjaqw")
                                .withTags(
                                    mapOf(
                                        "gjvw",
                                        "sprozvcput",
                                        "dvpjhulsuuvmk",
                                        "fdatsc",
                                        "jdpvwryo",
                                        "ozkrwfndiodjpslw"))
                                .withDataLocation("oxzjnchgejspod")
                                .withLinkedDomains(Arrays.asList()),
                            new CommunicationServiceResourceInner()
                                .withLocation("mayhuybbkpodepoo")
                                .withTags(
                                    mapOf("eotusivyevc", "uvamiheognarxzxt", "un", "iqihn", "fygxgispemvtzfk", "bwjzr"))
                                .withDataLocation("qtrgqjbpfzfsinzg")
                                .withLinkedDomains(Arrays.asList())))
                .withNextLink("qulngsntnbybkzgc");
        model = BinaryData.fromObject(model).toObject(CommunicationServiceResourceList.class);
        Assertions.assertEquals("mqnjaqw", model.value().get(0).location());
        Assertions.assertEquals("sprozvcput", model.value().get(0).tags().get("gjvw"));
        Assertions.assertEquals("oxzjnchgejspod", model.value().get(0).dataLocation());
        Assertions.assertEquals("qulngsntnbybkzgc", 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;
    }
}
