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

package com.azure.resourcemanager.newrelicobservability.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.newrelicobservability.fluent.models.NewRelicMonitorResourceInner;
import com.azure.resourcemanager.newrelicobservability.models.AccountCreationSource;
import com.azure.resourcemanager.newrelicobservability.models.ManagedServiceIdentity;
import com.azure.resourcemanager.newrelicobservability.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.newrelicobservability.models.NewRelicMonitorResourceListResult;
import com.azure.resourcemanager.newrelicobservability.models.OrgCreationSource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class NewRelicMonitorResourceListResultTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        NewRelicMonitorResourceListResult model =
            BinaryData
                .fromString(
                    "{\"value\":[{\"properties\":{\"provisioningState\":\"Creating\",\"monitoringStatus\":\"Enabled\",\"marketplaceSubscriptionStatus\":\"Active\",\"marketplaceSubscriptionId\":\"dio\",\"liftrResourceCategory\":\"Unknown\",\"liftrResourcePreference\":2028392349,\"orgCreationSource\":\"NEWRELIC\",\"accountCreationSource\":\"NEWRELIC\"},\"identity\":{\"principalId\":\"08951b99-ca13-4bdc-8322-11806828a442\",\"tenantId\":\"79c88631-a94e-42f2-98e2-666dbc928c5f\",\"type\":\"UserAssigned\",\"userAssignedIdentities\":{}},\"location\":\"oacctaza\",\"tags\":{\"fdosyg\":\"lahbcryff\"},\"id\":\"xpaojakhmsbz\",\"name\":\"hcrzevd\",\"type\":\"hlxaolthqtr\"},{\"properties\":{\"provisioningState\":\"Accepted\",\"monitoringStatus\":\"Disabled\",\"marketplaceSubscriptionStatus\":\"Suspended\",\"marketplaceSubscriptionId\":\"s\",\"liftrResourceCategory\":\"Unknown\",\"liftrResourcePreference\":1595507269,\"orgCreationSource\":\"LIFTR\",\"accountCreationSource\":\"NEWRELIC\"},\"identity\":{\"principalId\":\"e5702e62-e947-47d1-91f9-508630ba078a\",\"tenantId\":\"8352b2cc-4a40-45aa-9eab-5bae81f94e26\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{}},\"location\":\"lluwfzitonpeq\",\"tags\":{\"xypininmayhuybbk\":\"kjlxofpdvhpf\",\"vamih\":\"odepoogin\",\"vyevcciqi\":\"ognarxzxtheotus\",\"zrnf\":\"nhungbw\"},\"id\":\"gxg\",\"name\":\"spemvtzfk\",\"type\":\"fublj\"},{\"properties\":{\"provisioningState\":\"Deleting\",\"monitoringStatus\":\"Disabled\",\"marketplaceSubscriptionStatus\":\"Active\",\"marketplaceSubscriptionId\":\"aeqjhqjbasvms\",\"liftrResourceCategory\":\"MonitorLogs\",\"liftrResourcePreference\":951964300,\"orgCreationSource\":\"LIFTR\",\"accountCreationSource\":\"NEWRELIC\"},\"identity\":{\"principalId\":\"7ea6bb96-e02c-41b8-bb30-8f33eb3a80a4\",\"tenantId\":\"27310914-912e-4105-abf8-2ac41b52c5d5\",\"type\":\"SystemAssigned\",\"userAssignedIdentities\":{}},\"location\":\"wrwclxxwrljd\",\"tags\":{\"dkwt\":\"kcqvkocrc\",\"ssainqpjwnzll\":\"hxbnjbiksqrg\",\"bvmgxsabkyqduuji\":\"fmppe\"},\"id\":\"c\",\"name\":\"czdzev\",\"type\":\"dhkrwpdappdsbdk\"}],\"nextLink\":\"rwjfe\"}")
                .toObject(NewRelicMonitorResourceListResult.class);
        Assertions.assertEquals("oacctaza", model.value().get(0).location());
        Assertions.assertEquals("lahbcryff", model.value().get(0).tags().get("fdosyg"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals(OrgCreationSource.NEWRELIC, model.value().get(0).orgCreationSource());
        Assertions.assertEquals(AccountCreationSource.NEWRELIC, model.value().get(0).accountCreationSource());
        Assertions.assertEquals("rwjfe", model.nextLink());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        NewRelicMonitorResourceListResult model =
            new NewRelicMonitorResourceListResult()
                .withValue(
                    Arrays
                        .asList(
                            new NewRelicMonitorResourceInner()
                                .withLocation("oacctaza")
                                .withTags(mapOf("fdosyg", "lahbcryff"))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.USER_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withOrgCreationSource(OrgCreationSource.NEWRELIC)
                                .withAccountCreationSource(AccountCreationSource.NEWRELIC),
                            new NewRelicMonitorResourceInner()
                                .withLocation("lluwfzitonpeq")
                                .withTags(
                                    mapOf(
                                        "xypininmayhuybbk",
                                        "kjlxofpdvhpf",
                                        "vamih",
                                        "odepoogin",
                                        "vyevcciqi",
                                        "ognarxzxtheotus",
                                        "zrnf",
                                        "nhungbw"))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withOrgCreationSource(OrgCreationSource.LIFTR)
                                .withAccountCreationSource(AccountCreationSource.NEWRELIC),
                            new NewRelicMonitorResourceInner()
                                .withLocation("wrwclxxwrljd")
                                .withTags(
                                    mapOf(
                                        "dkwt",
                                        "kcqvkocrc",
                                        "ssainqpjwnzll",
                                        "hxbnjbiksqrg",
                                        "bvmgxsabkyqduuji",
                                        "fmppe"))
                                .withIdentity(
                                    new ManagedServiceIdentity()
                                        .withType(ManagedServiceIdentityType.SYSTEM_ASSIGNED)
                                        .withUserAssignedIdentities(mapOf()))
                                .withOrgCreationSource(OrgCreationSource.LIFTR)
                                .withAccountCreationSource(AccountCreationSource.NEWRELIC)))
                .withNextLink("rwjfe");
        model = BinaryData.fromObject(model).toObject(NewRelicMonitorResourceListResult.class);
        Assertions.assertEquals("oacctaza", model.value().get(0).location());
        Assertions.assertEquals("lahbcryff", model.value().get(0).tags().get("fdosyg"));
        Assertions.assertEquals(ManagedServiceIdentityType.USER_ASSIGNED, model.value().get(0).identity().type());
        Assertions.assertEquals(OrgCreationSource.NEWRELIC, model.value().get(0).orgCreationSource());
        Assertions.assertEquals(AccountCreationSource.NEWRELIC, model.value().get(0).accountCreationSource());
        Assertions.assertEquals("rwjfe", 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;
    }
}
