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

com.azure.resourcemanager.billing.fluent.models.PatchProperties 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.fluent.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.CoreUtils;
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.models.AppliedScopeType;
import com.azure.resourcemanager.billing.models.InstanceFlexibility;
import com.azure.resourcemanager.billing.models.ReservationAppliedScopeProperties;
import com.azure.resourcemanager.billing.models.ReservationPurchaseRequest;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Properties for reservation patch.
 */
@Fluent
public final class PatchProperties implements JsonSerializable {
    /*
     * Type of the Applied Scope.
     */
    private AppliedScopeType appliedScopeType;

    /*
     * Properties specific to applied scope type. Not required if not applicable. Required and need to provide tenantId
     * and managementGroupId if AppliedScopeType is ManagementGroup
     */
    private ReservationAppliedScopeProperties appliedScopeProperties;

    /*
     * Turning this on will apply the reservation discount to other VMs in the same VM size group. Only specify for
     * VirtualMachines reserved resource type.
     */
    private InstanceFlexibility instanceFlexibility;

    /*
     * Display name of the reservation
     */
    private String displayName;

    /*
     * Setting this to true will automatically purchase a new benefit on the expiration date time.
     */
    private Boolean renew;

    /*
     * The renewProperties property.
     */
    private PatchPropertiesRenewProperties innerRenewProperties;

    /*
     * This is the date-time when the Azure hybrid benefit needs to be reviewed.
     */
    private OffsetDateTime reviewDateTime;

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

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

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

    /**
     * Get the appliedScopeProperties property: Properties specific to applied scope type. Not required if not
     * applicable. Required and need to provide tenantId and managementGroupId if AppliedScopeType is ManagementGroup.
     * 
     * @return the appliedScopeProperties value.
     */
    public ReservationAppliedScopeProperties appliedScopeProperties() {
        return this.appliedScopeProperties;
    }

    /**
     * Set the appliedScopeProperties property: Properties specific to applied scope type. Not required if not
     * applicable. Required and need to provide tenantId and managementGroupId if AppliedScopeType is ManagementGroup.
     * 
     * @param appliedScopeProperties the appliedScopeProperties value to set.
     * @return the PatchProperties object itself.
     */
    public PatchProperties withAppliedScopeProperties(ReservationAppliedScopeProperties appliedScopeProperties) {
        this.appliedScopeProperties = appliedScopeProperties;
        return this;
    }

    /**
     * Get the instanceFlexibility property: Turning this on will apply the reservation discount to other VMs in the
     * same VM size group. Only specify for VirtualMachines reserved resource type.
     * 
     * @return the instanceFlexibility value.
     */
    public InstanceFlexibility instanceFlexibility() {
        return this.instanceFlexibility;
    }

    /**
     * Set the instanceFlexibility property: Turning this on will apply the reservation discount to other VMs in the
     * same VM size group. Only specify for VirtualMachines reserved resource type.
     * 
     * @param instanceFlexibility the instanceFlexibility value to set.
     * @return the PatchProperties object itself.
     */
    public PatchProperties withInstanceFlexibility(InstanceFlexibility instanceFlexibility) {
        this.instanceFlexibility = instanceFlexibility;
        return this;
    }

    /**
     * Get the displayName property: Display name of the reservation.
     * 
     * @return the displayName value.
     */
    public String displayName() {
        return this.displayName;
    }

    /**
     * Set the displayName property: Display name of the reservation.
     * 
     * @param displayName the displayName value to set.
     * @return the PatchProperties object itself.
     */
    public PatchProperties withDisplayName(String displayName) {
        this.displayName = displayName;
        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.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 PatchProperties object itself.
     */
    public PatchProperties withRenew(Boolean renew) {
        this.renew = renew;
        return this;
    }

    /**
     * Get the innerRenewProperties property: The renewProperties property.
     * 
     * @return the innerRenewProperties value.
     */
    private PatchPropertiesRenewProperties innerRenewProperties() {
        return this.innerRenewProperties;
    }

    /**
     * Get the reviewDateTime property: This is the date-time when the Azure hybrid benefit needs to be reviewed.
     * 
     * @return the reviewDateTime value.
     */
    public OffsetDateTime reviewDateTime() {
        return this.reviewDateTime;
    }

    /**
     * Set the reviewDateTime property: This is the date-time when the Azure hybrid benefit needs to be reviewed.
     * 
     * @param reviewDateTime the reviewDateTime value to set.
     * @return the PatchProperties object itself.
     */
    public PatchProperties withReviewDateTime(OffsetDateTime reviewDateTime) {
        this.reviewDateTime = reviewDateTime;
        return this;
    }

    /**
     * Get the purchaseProperties property: The request for reservation purchase.
     * 
     * @return the purchaseProperties value.
     */
    public ReservationPurchaseRequest purchaseProperties() {
        return this.innerRenewProperties() == null ? null : this.innerRenewProperties().purchaseProperties();
    }

    /**
     * Set the purchaseProperties property: The request for reservation purchase.
     * 
     * @param purchaseProperties the purchaseProperties value to set.
     * @return the PatchProperties object itself.
     */
    public PatchProperties withPurchaseProperties(ReservationPurchaseRequest purchaseProperties) {
        if (this.innerRenewProperties() == null) {
            this.innerRenewProperties = new PatchPropertiesRenewProperties();
        }
        this.innerRenewProperties().withPurchaseProperties(purchaseProperties);
        return this;
    }

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("appliedScopeType",
            this.appliedScopeType == null ? null : this.appliedScopeType.toString());
        jsonWriter.writeJsonField("appliedScopeProperties", this.appliedScopeProperties);
        jsonWriter.writeStringField("instanceFlexibility",
            this.instanceFlexibility == null ? null : this.instanceFlexibility.toString());
        jsonWriter.writeStringField("displayName", this.displayName);
        jsonWriter.writeBooleanField("renew", this.renew);
        jsonWriter.writeJsonField("renewProperties", this.innerRenewProperties);
        jsonWriter.writeStringField("reviewDateTime",
            this.reviewDateTime == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.reviewDateTime));
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of PatchProperties from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of PatchProperties 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 PatchProperties.
     */
    public static PatchProperties fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            PatchProperties deserializedPatchProperties = new PatchProperties();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("appliedScopeType".equals(fieldName)) {
                    deserializedPatchProperties.appliedScopeType = AppliedScopeType.fromString(reader.getString());
                } else if ("appliedScopeProperties".equals(fieldName)) {
                    deserializedPatchProperties.appliedScopeProperties
                        = ReservationAppliedScopeProperties.fromJson(reader);
                } else if ("instanceFlexibility".equals(fieldName)) {
                    deserializedPatchProperties.instanceFlexibility
                        = InstanceFlexibility.fromString(reader.getString());
                } else if ("displayName".equals(fieldName)) {
                    deserializedPatchProperties.displayName = reader.getString();
                } else if ("renew".equals(fieldName)) {
                    deserializedPatchProperties.renew = reader.getNullable(JsonReader::getBoolean);
                } else if ("renewProperties".equals(fieldName)) {
                    deserializedPatchProperties.innerRenewProperties = PatchPropertiesRenewProperties.fromJson(reader);
                } else if ("reviewDateTime".equals(fieldName)) {
                    deserializedPatchProperties.reviewDateTime = reader
                        .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedPatchProperties;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy