All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.resourcemanager.billing.models.PurchaseRequest Maven / Gradle / Ivy

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

package com.azure.resourcemanager.billing.models;

import com.azure.core.annotation.Fluent;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import com.azure.resourcemanager.billing.fluent.models.PurchaseRequestProperties;
import java.io.IOException;

/**
 * Purchase request.
 */
@Fluent
public final class PurchaseRequest implements JsonSerializable {
    /*
     * The SKU to be applied for this resource
     */
    private Sku sku;

    /*
     * Purchase request properties.
     */
    private PurchaseRequestProperties innerProperties;

    /**
     * Creates an instance of PurchaseRequest class.
     */
    public PurchaseRequest() {
    }

    /**
     * Get the sku property: The SKU to be applied for this resource.
     * 
     * @return the sku value.
     */
    public Sku sku() {
        return this.sku;
    }

    /**
     * Set the sku property: The SKU to be applied for this resource.
     * 
     * @param sku the sku value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withSku(Sku sku) {
        this.sku = sku;
        return this;
    }

    /**
     * Get the innerProperties property: Purchase request properties.
     * 
     * @return the innerProperties value.
     */
    private PurchaseRequestProperties innerProperties() {
        return this.innerProperties;
    }

    /**
     * Get the displayName property: Friendly name of the savings plan.
     * 
     * @return the displayName value.
     */
    public String displayName() {
        return this.innerProperties() == null ? null : this.innerProperties().displayName();
    }

    /**
     * Set the displayName property: Friendly name of the savings plan.
     * 
     * @param displayName the displayName value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withDisplayName(String displayName) {
        if (this.innerProperties() == null) {
            this.innerProperties = new PurchaseRequestProperties();
        }
        this.innerProperties().withDisplayName(displayName);
        return this;
    }

    /**
     * Get the billingScopeId property: Subscription that will be charged for purchasing SavingsPlan.
     * 
     * @return the billingScopeId value.
     */
    public String billingScopeId() {
        return this.innerProperties() == null ? null : this.innerProperties().billingScopeId();
    }

    /**
     * Set the billingScopeId property: Subscription that will be charged for purchasing SavingsPlan.
     * 
     * @param billingScopeId the billingScopeId value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withBillingScopeId(String billingScopeId) {
        if (this.innerProperties() == null) {
            this.innerProperties = new PurchaseRequestProperties();
        }
        this.innerProperties().withBillingScopeId(billingScopeId);
        return this;
    }

    /**
     * Get the term property: Represents the Savings plan term in ISO 8601 format.
     * 
     * @return the term value.
     */
    public SavingsPlanTerm term() {
        return this.innerProperties() == null ? null : this.innerProperties().term();
    }

    /**
     * Set the term property: Represents the Savings plan term in ISO 8601 format.
     * 
     * @param term the term value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withTerm(SavingsPlanTerm term) {
        if (this.innerProperties() == null) {
            this.innerProperties = new PurchaseRequestProperties();
        }
        this.innerProperties().withTerm(term);
        return this;
    }

    /**
     * Get the billingPlan property: Represents the billing plan in ISO 8601 format. Required only for monthly
     * purchases.
     * 
     * @return the billingPlan value.
     */
    public BillingPlan billingPlan() {
        return this.innerProperties() == null ? null : this.innerProperties().billingPlan();
    }

    /**
     * Set the billingPlan property: Represents the billing plan in ISO 8601 format. Required only for monthly
     * purchases.
     * 
     * @param billingPlan the billingPlan value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withBillingPlan(BillingPlan billingPlan) {
        if (this.innerProperties() == null) {
            this.innerProperties = new PurchaseRequestProperties();
        }
        this.innerProperties().withBillingPlan(billingPlan);
        return this;
    }

    /**
     * Get the appliedScopeType property: Type of the Applied Scope.
     * 
     * @return the appliedScopeType value.
     */
    public AppliedScopeType appliedScopeType() {
        return this.innerProperties() == null ? null : this.innerProperties().appliedScopeType();
    }

    /**
     * Set the appliedScopeType property: Type of the Applied Scope.
     * 
     * @param appliedScopeType the appliedScopeType value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withAppliedScopeType(AppliedScopeType appliedScopeType) {
        if (this.innerProperties() == null) {
            this.innerProperties = new PurchaseRequestProperties();
        }
        this.innerProperties().withAppliedScopeType(appliedScopeType);
        return this;
    }

    /**
     * Get the commitment property: Commitment towards the benefit.
     * 
     * @return the commitment value.
     */
    public Commitment commitment() {
        return this.innerProperties() == null ? null : this.innerProperties().commitment();
    }

    /**
     * Set the commitment property: Commitment towards the benefit.
     * 
     * @param commitment the commitment value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withCommitment(Commitment commitment) {
        if (this.innerProperties() == null) {
            this.innerProperties = new PurchaseRequestProperties();
        }
        this.innerProperties().withCommitment(commitment);
        return this;
    }

    /**
     * Get the renew property: Setting this to true will automatically purchase a new benefit on the expiration date
     * time.
     * 
     * @return the renew value.
     */
    public Boolean renew() {
        return this.innerProperties() == null ? null : this.innerProperties().renew();
    }

    /**
     * Set the renew property: Setting this to true will automatically purchase a new benefit on the expiration date
     * time.
     * 
     * @param renew the renew value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withRenew(Boolean renew) {
        if (this.innerProperties() == null) {
            this.innerProperties = new PurchaseRequestProperties();
        }
        this.innerProperties().withRenew(renew);
        return this;
    }

    /**
     * Get the appliedScopeProperties property: Properties specific to applied scope type. Not required if not
     * applicable.
     * 
     * @return the appliedScopeProperties value.
     */
    public AppliedScopeProperties appliedScopeProperties() {
        return this.innerProperties() == null ? null : this.innerProperties().appliedScopeProperties();
    }

    /**
     * Set the appliedScopeProperties property: Properties specific to applied scope type. Not required if not
     * applicable.
     * 
     * @param appliedScopeProperties the appliedScopeProperties value to set.
     * @return the PurchaseRequest object itself.
     */
    public PurchaseRequest withAppliedScopeProperties(AppliedScopeProperties appliedScopeProperties) {
        if (this.innerProperties() == null) {
            this.innerProperties = new PurchaseRequestProperties();
        }
        this.innerProperties().withAppliedScopeProperties(appliedScopeProperties);
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (sku() != null) {
            sku().validate();
        }
        if (innerProperties() != null) {
            innerProperties().validate();
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeJsonField("sku", this.sku);
        jsonWriter.writeJsonField("properties", this.innerProperties);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of PurchaseRequest from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of PurchaseRequest if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IOException If an error occurs while reading the PurchaseRequest.
     */
    public static PurchaseRequest fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            PurchaseRequest deserializedPurchaseRequest = new PurchaseRequest();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("sku".equals(fieldName)) {
                    deserializedPurchaseRequest.sku = Sku.fromJson(reader);
                } else if ("properties".equals(fieldName)) {
                    deserializedPurchaseRequest.innerProperties = PurchaseRequestProperties.fromJson(reader);
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedPurchaseRequest;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy