// 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.EmailServiceResourceInner;
import com.azure.resourcemanager.communication.models.EmailServiceResourceList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class EmailServiceResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        EmailServiceResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"provisioningState\":\"Succeeded\",\"dataLocation\":\"ypvhezrkg\"},\"location\":\"c\",\"tags\":{\"jpkcattpng\":\"fovgmkqsleyyvxy\",\"czsqpjhvm\":\"cr\"},\"id\":\"ajvnysounqe\",\"name\":\"a\",\"type\":\"oaeupfhyhltrpmo\"},{\"properties\":{\"provisioningState\":\"Updating\",\"dataLocation\":\"matuok\"},\"location\":\"fu\",\"tags\":{\"zydagfuaxbezyiuo\":\"odsfcpkvxodpuozm\",\"dxwzywqsmbsurexi\":\"ktwh\",\"yocf\":\"o\"},\"id\":\"fksymddystki\",\"name\":\"uxh\",\"type\":\"yudxorrqnbp\"}],\"nextLink\":\"zvyifqrvkdvj\"}")
                .toObject(EmailServiceResourceList.class);
        Assertions.assertEquals("c", model.value().get(0).location());
        Assertions.assertEquals("fovgmkqsleyyvxy", model.value().get(0).tags().get("jpkcattpng"));
        Assertions.assertEquals("ypvhezrkg", model.value().get(0).dataLocation());
        Assertions.assertEquals("zvyifqrvkdvj", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        EmailServiceResourceList model =
            new EmailServiceResourceList()
                .withValue(
                    Arrays
                        .asList(
                            new EmailServiceResourceInner()
                                .withLocation("c")
                                .withTags(mapOf("jpkcattpng", "fovgmkqsleyyvxy", "czsqpjhvm", "cr"))
                                .withDataLocation("ypvhezrkg"),
                            new EmailServiceResourceInner()
                                .withLocation("fu")
                                .withTags(
                                    mapOf(
                                        "zydagfuaxbezyiuo",
                                        "odsfcpkvxodpuozm",
                                        "dxwzywqsmbsurexi",
                                        "ktwh",
                                        "yocf",
                                        "o"))
                                .withDataLocation("matuok")))
                .withNextLink("zvyifqrvkdvj");
        model = BinaryData.fromObject(model).toObject(EmailServiceResourceList.class);
        Assertions.assertEquals("c", model.value().get(0).location());
        Assertions.assertEquals("fovgmkqsleyyvxy", model.value().get(0).tags().get("jpkcattpng"));
        Assertions.assertEquals("ypvhezrkg", model.value().get(0).dataLocation());
        Assertions.assertEquals("zvyifqrvkdvj", 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;
    }
}
