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

package com.azure.resourcemanager.reservations.generated;

import com.azure.core.util.BinaryData;
import com.azure.resourcemanager.reservations.models.AppliedScopeProperties;
import com.azure.resourcemanager.reservations.models.AppliedScopeType;
import com.azure.resourcemanager.reservations.models.InstanceFlexibility;
import com.azure.resourcemanager.reservations.models.PurchaseRequest;
import com.azure.resourcemanager.reservations.models.PurchaseRequestPropertiesReservedResourceProperties;
import com.azure.resourcemanager.reservations.models.ReservationBillingPlan;
import com.azure.resourcemanager.reservations.models.ReservationTerm;
import com.azure.resourcemanager.reservations.models.ReservedResourceType;
import com.azure.resourcemanager.reservations.models.SkuName;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;

public final class PurchaseRequestTests {
    @org.junit.jupiter.api.Test
    public void testDeserialize() throws Exception {
        PurchaseRequest model =
            BinaryData
                .fromString(
                    "{\"sku\":{\"name\":\"bljofxqeof\"},\"location\":\"e\",\"properties\":{\"reservedResourceType\":\"RedHatOsa\",\"billingScopeId\":\"b\",\"term\":\"P1Y\",\"billingPlan\":\"Monthly\",\"quantity\":928331689,\"displayName\":\"ulngsntn\",\"appliedScopeType\":\"Shared\",\"appliedScopes\":[\"gc\",\"rwclxxwrljdo\"],\"appliedScopeProperties\":{\"tenantId\":\"cqvkocrcjdkwtn\",\"managementGroupId\":\"bnjbiksqrglssain\",\"subscriptionId\":\"jwnzlljfmp\",\"resourceGroupId\":\"ebvmgxsabkyqd\",\"displayName\":\"jitcjczdzevn\"},\"renew\":false,\"reservedResourceProperties\":{\"instanceFlexibility\":\"On\"},\"reviewDateTime\":\"2021-04-18T17:34:07Z\"}}")
                .toObject(PurchaseRequest.class);
        Assertions.assertEquals("bljofxqeof", model.sku().name());
        Assertions.assertEquals("e", model.location());
        Assertions.assertEquals(ReservedResourceType.RED_HAT_OSA, model.reservedResourceType());
        Assertions.assertEquals("b", model.billingScopeId());
        Assertions.assertEquals(ReservationTerm.P1Y, model.term());
        Assertions.assertEquals(ReservationBillingPlan.MONTHLY, model.billingPlan());
        Assertions.assertEquals(928331689, model.quantity());
        Assertions.assertEquals("ulngsntn", model.displayName());
        Assertions.assertEquals(AppliedScopeType.SHARED, model.appliedScopeType());
        Assertions.assertEquals("gc", model.appliedScopes().get(0));
        Assertions.assertEquals("cqvkocrcjdkwtn", model.appliedScopeProperties().tenantId());
        Assertions.assertEquals("bnjbiksqrglssain", model.appliedScopeProperties().managementGroupId());
        Assertions.assertEquals("jwnzlljfmp", model.appliedScopeProperties().subscriptionId());
        Assertions.assertEquals("ebvmgxsabkyqd", model.appliedScopeProperties().resourceGroupId());
        Assertions.assertEquals("jitcjczdzevn", model.appliedScopeProperties().displayName());
        Assertions.assertEquals(false, model.renew());
        Assertions.assertEquals(InstanceFlexibility.ON, model.reservedResourceProperties().instanceFlexibility());
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-18T17:34:07Z"), model.reviewDateTime());
    }

    @org.junit.jupiter.api.Test
    public void testSerialize() throws Exception {
        PurchaseRequest model =
            new PurchaseRequest()
                .withSku(new SkuName().withName("bljofxqeof"))
                .withLocation("e")
                .withReservedResourceType(ReservedResourceType.RED_HAT_OSA)
                .withBillingScopeId("b")
                .withTerm(ReservationTerm.P1Y)
                .withBillingPlan(ReservationBillingPlan.MONTHLY)
                .withQuantity(928331689)
                .withDisplayName("ulngsntn")
                .withAppliedScopeType(AppliedScopeType.SHARED)
                .withAppliedScopes(Arrays.asList("gc", "rwclxxwrljdo"))
                .withAppliedScopeProperties(
                    new AppliedScopeProperties()
                        .withTenantId("cqvkocrcjdkwtn")
                        .withManagementGroupId("bnjbiksqrglssain")
                        .withSubscriptionId("jwnzlljfmp")
                        .withResourceGroupId("ebvmgxsabkyqd")
                        .withDisplayName("jitcjczdzevn"))
                .withRenew(false)
                .withReservedResourceProperties(
                    new PurchaseRequestPropertiesReservedResourceProperties()
                        .withInstanceFlexibility(InstanceFlexibility.ON))
                .withReviewDateTime(OffsetDateTime.parse("2021-04-18T17:34:07Z"));
        model = BinaryData.fromObject(model).toObject(PurchaseRequest.class);
        Assertions.assertEquals("bljofxqeof", model.sku().name());
        Assertions.assertEquals("e", model.location());
        Assertions.assertEquals(ReservedResourceType.RED_HAT_OSA, model.reservedResourceType());
        Assertions.assertEquals("b", model.billingScopeId());
        Assertions.assertEquals(ReservationTerm.P1Y, model.term());
        Assertions.assertEquals(ReservationBillingPlan.MONTHLY, model.billingPlan());
        Assertions.assertEquals(928331689, model.quantity());
        Assertions.assertEquals("ulngsntn", model.displayName());
        Assertions.assertEquals(AppliedScopeType.SHARED, model.appliedScopeType());
        Assertions.assertEquals("gc", model.appliedScopes().get(0));
        Assertions.assertEquals("cqvkocrcjdkwtn", model.appliedScopeProperties().tenantId());
        Assertions.assertEquals("bnjbiksqrglssain", model.appliedScopeProperties().managementGroupId());
        Assertions.assertEquals("jwnzlljfmp", model.appliedScopeProperties().subscriptionId());
        Assertions.assertEquals("ebvmgxsabkyqd", model.appliedScopeProperties().resourceGroupId());
        Assertions.assertEquals("jitcjczdzevn", model.appliedScopeProperties().displayName());
        Assertions.assertEquals(false, model.renew());
        Assertions.assertEquals(InstanceFlexibility.ON, model.reservedResourceProperties().instanceFlexibility());
        Assertions.assertEquals(OffsetDateTime.parse("2021-04-18T17:34:07Z"), model.reviewDateTime());
    }
}
