// 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.BillingCycle;
import com.azure.resourcemanager.newrelicobservability.models.ManagedServiceIdentity;
import com.azure.resourcemanager.newrelicobservability.models.ManagedServiceIdentityType;
import com.azure.resourcemanager.newrelicobservability.models.NewRelicAccountProperties;
import com.azure.resourcemanager.newrelicobservability.models.OrgCreationSource;
import com.azure.resourcemanager.newrelicobservability.models.PlanData;
import com.azure.resourcemanager.newrelicobservability.models.UsageType;
import com.azure.resourcemanager.newrelicobservability.models.UserAssignedIdentity;
import com.azure.resourcemanager.newrelicobservability.models.UserInfo;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;

public final class NewRelicMonitorResourceInnerTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        NewRelicMonitorResourceInner model =
            BinaryData
                .fromString(
                    "{\"properties\":{\"provisioningState\":\"Accepted\",\"monitoringStatus\":\"Disabled\",\"marketplaceSubscriptionStatus\":\"Active\",\"marketplaceSubscriptionId\":\"ltmrldh\",\"newRelicAccountProperties\":{\"userId\":\"zzd\"},\"userInfo\":{\"firstName\":\"cdgea\",\"lastName\":\"gphuticndvka\",\"emailAddress\":\"wyiftyhxhur\",\"phoneNumber\":\"ftyxolniw\",\"country\":\"cukjf\"},\"planData\":{\"usageType\":\"PAYG\",\"billingCycle\":\"MONTHLY\",\"planDetails\":\"lryplwckbasyy\",\"effectiveDate\":\"2021-05-24T00:31:31Z\"},\"liftrResourceCategory\":\"MonitorLogs\",\"liftrResourcePreference\":1048772360,\"orgCreationSource\":\"NEWRELIC\",\"accountCreationSource\":\"LIFTR\"},\"identity\":{\"principalId\":\"17917958-feea-475b-924d-d460356abeb7\",\"tenantId\":\"0c6581b4-9dc9-4139-9af6-885e2ea5f76d\",\"type\":\"None\",\"userAssignedIdentities\":{\"nqgoulzndli\":{\"principalId\":\"1441313f-47dc-4ce5-b867-17a8c2992b93\",\"clientId\":\"0c0cf59f-46a6-479e-954b-b32c3748fb4f\"}}},\"location\":\"yqkgfg\",\"tags\":{\"qedqytbciqfoufl\":\"adgakeqsrxybz\",\"glougpbk\":\"mnkzsmod\",\"uqktap\":\"tmut\",\"kdosvqw\":\"pwgcuertu\"},\"id\":\"bmdg\",\"name\":\"bjf\",\"type\":\"dgmb\"}")
                .toObject(NewRelicMonitorResourceInner.class);
        Assertions.assertEquals("yqkgfg", model.location());
        Assertions.assertEquals("adgakeqsrxybz", model.tags().get("qedqytbciqfoufl"));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals("zzd", model.newRelicAccountProperties().userId());
        Assertions.assertEquals("cdgea", model.userInfo().firstName());
        Assertions.assertEquals("gphuticndvka", model.userInfo().lastName());
        Assertions.assertEquals("wyiftyhxhur", model.userInfo().emailAddress());
        Assertions.assertEquals("ftyxolniw", model.userInfo().phoneNumber());
        Assertions.assertEquals("cukjf", model.userInfo().country());
        Assertions.assertEquals(UsageType.PAYG, model.planData().usageType());
        Assertions.assertEquals(BillingCycle.MONTHLY, model.planData().billingCycle());
        Assertions.assertEquals("lryplwckbasyy", model.planData().planDetails());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-24T00:31:31Z"), model.planData().effectiveDate());
        Assertions.assertEquals(OrgCreationSource.NEWRELIC, model.orgCreationSource());
        Assertions.assertEquals(AccountCreationSource.LIFTR, model.accountCreationSource());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        NewRelicMonitorResourceInner model =
            new NewRelicMonitorResourceInner()
                .withLocation("yqkgfg")
                .withTags(
                    mapOf(
                        "qedqytbciqfoufl",
                        "adgakeqsrxybz",
                        "glougpbk",
                        "mnkzsmod",
                        "uqktap",
                        "tmut",
                        "kdosvqw",
                        "pwgcuertu"))
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.NONE)
                        .withUserAssignedIdentities(mapOf("nqgoulzndli", new UserAssignedIdentity())))
                .withNewRelicAccountProperties(new NewRelicAccountProperties().withUserId("zzd"))
                .withUserInfo(
                    new UserInfo()
                        .withFirstName("cdgea")
                        .withLastName("gphuticndvka")
                        .withEmailAddress("wyiftyhxhur")
                        .withPhoneNumber("ftyxolniw")
                        .withCountry("cukjf"))
                .withPlanData(
                    new PlanData()
                        .withUsageType(UsageType.PAYG)
                        .withBillingCycle(BillingCycle.MONTHLY)
                        .withPlanDetails("lryplwckbasyy")
                        .withEffectiveDate(OffsetDateTime.parse("2021-05-24T00:31:31Z")))
                .withOrgCreationSource(OrgCreationSource.NEWRELIC)
                .withAccountCreationSource(AccountCreationSource.LIFTR);
        model = BinaryData.fromObject(model).toObject(NewRelicMonitorResourceInner.class);
        Assertions.assertEquals("yqkgfg", model.location());
        Assertions.assertEquals("adgakeqsrxybz", model.tags().get("qedqytbciqfoufl"));
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals("zzd", model.newRelicAccountProperties().userId());
        Assertions.assertEquals("cdgea", model.userInfo().firstName());
        Assertions.assertEquals("gphuticndvka", model.userInfo().lastName());
        Assertions.assertEquals("wyiftyhxhur", model.userInfo().emailAddress());
        Assertions.assertEquals("ftyxolniw", model.userInfo().phoneNumber());
        Assertions.assertEquals("cukjf", model.userInfo().country());
        Assertions.assertEquals(UsageType.PAYG, model.planData().usageType());
        Assertions.assertEquals(BillingCycle.MONTHLY, model.planData().billingCycle());
        Assertions.assertEquals("lryplwckbasyy", model.planData().planDetails());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-24T00:31:31Z"), model.planData().effectiveDate());
        Assertions.assertEquals(OrgCreationSource.NEWRELIC, model.orgCreationSource());
        Assertions.assertEquals(AccountCreationSource.LIFTR, model.accountCreationSource());
    }

    @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;
    }
}
