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

com.azure.resourcemanager.billing.models.CustomerPolicyProperties 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.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;

/**
 * A policy at customer scope.
 */
@Fluent
public final class CustomerPolicyProperties implements JsonSerializable {
    /*
     * The provisioning state of the resource during a long-running operation.
     */
    private ProvisioningState provisioningState;

    /*
     * The policy that controls whether the users in customer's organization can view charges at pay-as-you-go prices.
     */
    private ViewChargesPolicy viewCharges;

    /*
     * List of all policies defined at the billing scope.
     */
    private List policies;

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

    /**
     * Get the provisioningState property: The provisioning state of the resource during a long-running operation.
     * 
     * @return the provisioningState value.
     */
    public ProvisioningState provisioningState() {
        return this.provisioningState;
    }

    /**
     * Get the viewCharges property: The policy that controls whether the users in customer's organization can view
     * charges at pay-as-you-go prices.
     * 
     * @return the viewCharges value.
     */
    public ViewChargesPolicy viewCharges() {
        return this.viewCharges;
    }

    /**
     * Set the viewCharges property: The policy that controls whether the users in customer's organization can view
     * charges at pay-as-you-go prices.
     * 
     * @param viewCharges the viewCharges value to set.
     * @return the CustomerPolicyProperties object itself.
     */
    public CustomerPolicyProperties withViewCharges(ViewChargesPolicy viewCharges) {
        this.viewCharges = viewCharges;
        return this;
    }

    /**
     * Get the policies property: List of all policies defined at the billing scope.
     * 
     * @return the policies value.
     */
    public List policies() {
        return this.policies;
    }

    /**
     * Set the policies property: List of all policies defined at the billing scope.
     * 
     * @param policies the policies value to set.
     * @return the CustomerPolicyProperties object itself.
     */
    public CustomerPolicyProperties withPolicies(List policies) {
        this.policies = policies;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (viewCharges() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property viewCharges in model CustomerPolicyProperties"));
        }
        if (policies() != null) {
            policies().forEach(e -> e.validate());
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(CustomerPolicyProperties.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("viewCharges", this.viewCharges == null ? null : this.viewCharges.toString());
        jsonWriter.writeArrayField("policies", this.policies, (writer, element) -> writer.writeJson(element));
        return jsonWriter.writeEndObject();
    }

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

                if ("viewCharges".equals(fieldName)) {
                    deserializedCustomerPolicyProperties.viewCharges = ViewChargesPolicy.fromString(reader.getString());
                } else if ("provisioningState".equals(fieldName)) {
                    deserializedCustomerPolicyProperties.provisioningState
                        = ProvisioningState.fromString(reader.getString());
                } else if ("policies".equals(fieldName)) {
                    List policies = reader.readArray(reader1 -> PolicySummary.fromJson(reader1));
                    deserializedCustomerPolicyProperties.policies = policies;
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedCustomerPolicyProperties;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy