// 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.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.NewRelicMonitorResourceUpdate;
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 NewRelicMonitorResourceUpdateTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        NewRelicMonitorResourceUpdate model =
            BinaryData
                .fromString(
                    "{\"identity\":{\"principalId\":\"8af364d0-2423-4107-bc81-1b490f4f4095\",\"tenantId\":\"c20fd884-bcd8-4a5a-9fa4-24f086f2191f\",\"type\":\"None\",\"userAssignedIdentities\":{\"ciwqvhk\":{\"principalId\":\"ac4a2a96-2e50-41e8-8716-1e44c18db630\",\"clientId\":\"aefefa77-aa8d-4e04-8ad5-d6ec26306953\"},\"uigdtopbobjog\":{\"principalId\":\"011ce17c-e213-4ecb-a551-6bb9fd7292be\",\"clientId\":\"7edf55c0-8c77-4501-ab62-0461a07096ec\"}}},\"tags\":{\"a\":\"w\"},\"properties\":{\"newRelicAccountProperties\":{\"userId\":\"rzayv\"},\"userInfo\":{\"firstName\":\"f\",\"lastName\":\"otkftutqxlngx\",\"emailAddress\":\"fgugnxkrxdqmid\",\"phoneNumber\":\"hzrvqd\",\"country\":\"bhj\"},\"planData\":{\"usageType\":\"COMMITTED\",\"billingCycle\":\"YEARLY\",\"planDetails\":\"qfbow\",\"effectiveDate\":\"2021-05-19T19:15:18Z\"},\"orgCreationSource\":\"LIFTR\",\"accountCreationSource\":\"NEWRELIC\"}}")
                .toObject(NewRelicMonitorResourceUpdate.class);
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals("w", model.tags().get("a"));
        Assertions.assertEquals("rzayv", model.newRelicAccountProperties().userId());
        Assertions.assertEquals("f", model.userInfo().firstName());
        Assertions.assertEquals("otkftutqxlngx", model.userInfo().lastName());
        Assertions.assertEquals("fgugnxkrxdqmid", model.userInfo().emailAddress());
        Assertions.assertEquals("hzrvqd", model.userInfo().phoneNumber());
        Assertions.assertEquals("bhj", model.userInfo().country());
        Assertions.assertEquals(UsageType.COMMITTED, model.planData().usageType());
        Assertions.assertEquals(BillingCycle.YEARLY, model.planData().billingCycle());
        Assertions.assertEquals("qfbow", model.planData().planDetails());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-19T19:15:18Z"), model.planData().effectiveDate());
        Assertions.assertEquals(OrgCreationSource.LIFTR, model.orgCreationSource());
        Assertions.assertEquals(AccountCreationSource.NEWRELIC, model.accountCreationSource());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        NewRelicMonitorResourceUpdate model =
            new NewRelicMonitorResourceUpdate()
                .withIdentity(
                    new ManagedServiceIdentity()
                        .withType(ManagedServiceIdentityType.NONE)
                        .withUserAssignedIdentities(
                            mapOf("ciwqvhk", new UserAssignedIdentity(), "uigdtopbobjog", new UserAssignedIdentity())))
                .withTags(mapOf("a", "w"))
                .withNewRelicAccountProperties(new NewRelicAccountProperties().withUserId("rzayv"))
                .withUserInfo(
                    new UserInfo()
                        .withFirstName("f")
                        .withLastName("otkftutqxlngx")
                        .withEmailAddress("fgugnxkrxdqmid")
                        .withPhoneNumber("hzrvqd")
                        .withCountry("bhj"))
                .withPlanData(
                    new PlanData()
                        .withUsageType(UsageType.COMMITTED)
                        .withBillingCycle(BillingCycle.YEARLY)
                        .withPlanDetails("qfbow")
                        .withEffectiveDate(OffsetDateTime.parse("2021-05-19T19:15:18Z")))
                .withOrgCreationSource(OrgCreationSource.LIFTR)
                .withAccountCreationSource(AccountCreationSource.NEWRELIC);
        model = BinaryData.fromObject(model).toObject(NewRelicMonitorResourceUpdate.class);
        Assertions.assertEquals(ManagedServiceIdentityType.NONE, model.identity().type());
        Assertions.assertEquals("w", model.tags().get("a"));
        Assertions.assertEquals("rzayv", model.newRelicAccountProperties().userId());
        Assertions.assertEquals("f", model.userInfo().firstName());
        Assertions.assertEquals("otkftutqxlngx", model.userInfo().lastName());
        Assertions.assertEquals("fgugnxkrxdqmid", model.userInfo().emailAddress());
        Assertions.assertEquals("hzrvqd", model.userInfo().phoneNumber());
        Assertions.assertEquals("bhj", model.userInfo().country());
        Assertions.assertEquals(UsageType.COMMITTED, model.planData().usageType());
        Assertions.assertEquals(BillingCycle.YEARLY, model.planData().billingCycle());
        Assertions.assertEquals("qfbow", model.planData().planDetails());
        Assertions.assertEquals(OffsetDateTime.parse("2021-05-19T19:15:18Z"), model.planData().effectiveDate());
        Assertions.assertEquals(OrgCreationSource.LIFTR, model.orgCreationSource());
        Assertions.assertEquals(AccountCreationSource.NEWRELIC, 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;
    }
}
