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

public final class DomainResourceListTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        DomainResourceList model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"provisioningState\":\"Unknown\",\"dataLocation\":\"jjxhvpmo\",\"fromSenderDomain\":\"xhdzxibqeojnx\",\"mailFromSenderDomain\":\"zvddntwndeicbtwn\",\"domainManagement\":\"AzureManaged\",\"userEngagementTracking\":\"Enabled\"},\"location\":\"hrhcffcyddglmjth\",\"tags\":{\"hix\":\"wpyeicxmqciwqvh\"},\"id\":\"igdtopbob\",\"name\":\"og\",\"type\":\"m\"},{\"properties\":{\"provisioningState\":\"Moving\",\"dataLocation\":\"a\",\"fromSenderDomain\":\"rzayv\",\"mailFromSenderDomain\":\"pgvdf\",\"domainManagement\":\"AzureManaged\",\"userEngagementTracking\":\"Enabled\"},\"location\":\"utqxlngx\",\"tags\":{\"xkrxdqmi\":\"gug\",\"abhjybi\":\"tthzrvqd\",\"ktzlcuiywg\":\"ehoqfbowskan\",\"nhzgpphrcgyn\":\"ywgndrv\"},\"id\":\"ocpecfvmmco\",\"name\":\"fsxlzevgbmqjqa\",\"type\":\"c\"},{\"properties\":{\"provisioningState\":\"Deleting\",\"dataLocation\":\"kwlzuvccfwnfn\",\"fromSenderDomain\":\"cfionl\",\"mailFromSenderDomain\":\"x\",\"domainManagement\":\"CustomerManagedInExchangeOnline\",\"userEngagementTracking\":\"Enabled\"},\"location\":\"dpnqbq\",\"tags\":{\"mpmngnzscxaqwoo\":\"rjfeallnwsubisnj\",\"njeaseipheofloke\":\"hcbonqvpkvlr\",\"enjbdlwtgrhp\":\"y\",\"umasxazjpq\":\"jp\"},\"id\":\"e\",\"name\":\"ualhbxxhejj\",\"type\":\"zvdudgwdslfhotwm\"}],\"nextLink\":\"npwlbjnpg\"}")
                .toObject(DomainResourceList.class);
        Assertions.assertEquals("hrhcffcyddglmjth", model.value().get(0).location());
        Assertions.assertEquals("wpyeicxmqciwqvh", model.value().get(0).tags().get("hix"));
        Assertions.assertEquals(DomainManagement.AZURE_MANAGED, model.value().get(0).domainManagement());
        Assertions.assertEquals(UserEngagementTracking.ENABLED, model.value().get(0).userEngagementTracking());
        Assertions.assertEquals("npwlbjnpg", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        DomainResourceList model =
            new DomainResourceList()
                .withValue(
                    Arrays
                        .asList(
                            new DomainResourceInner()
                                .withLocation("hrhcffcyddglmjth")
                                .withTags(mapOf("hix", "wpyeicxmqciwqvh"))
                                .withDomainManagement(DomainManagement.AZURE_MANAGED)
                                .withUserEngagementTracking(UserEngagementTracking.ENABLED),
                            new DomainResourceInner()
                                .withLocation("utqxlngx")
                                .withTags(
                                    mapOf(
                                        "xkrxdqmi",
                                        "gug",
                                        "abhjybi",
                                        "tthzrvqd",
                                        "ktzlcuiywg",
                                        "ehoqfbowskan",
                                        "nhzgpphrcgyn",
                                        "ywgndrv"))
                                .withDomainManagement(DomainManagement.AZURE_MANAGED)
                                .withUserEngagementTracking(UserEngagementTracking.ENABLED),
                            new DomainResourceInner()
                                .withLocation("dpnqbq")
                                .withTags(
                                    mapOf(
                                        "mpmngnzscxaqwoo",
                                        "rjfeallnwsubisnj",
                                        "njeaseipheofloke",
                                        "hcbonqvpkvlr",
                                        "enjbdlwtgrhp",
                                        "y",
                                        "umasxazjpq",
                                        "jp"))
                                .withDomainManagement(DomainManagement.CUSTOMER_MANAGED_IN_EXCHANGE_ONLINE)
                                .withUserEngagementTracking(UserEngagementTracking.ENABLED)))
                .withNextLink("npwlbjnpg");
        model = BinaryData.fromObject(model).toObject(DomainResourceList.class);
        Assertions.assertEquals("hrhcffcyddglmjth", model.value().get(0).location());
        Assertions.assertEquals("wpyeicxmqciwqvh", model.value().get(0).tags().get("hix"));
        Assertions.assertEquals(DomainManagement.AZURE_MANAGED, model.value().get(0).domainManagement());
        Assertions.assertEquals(UserEngagementTracking.ENABLED, model.value().get(0).userEngagementTracking());
        Assertions.assertEquals("npwlbjnpg", 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;
    }
}
