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

package azure.resourcemanager.operationtemplates.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 java.io.IOException;

/**
 * The ChangeAllowanceRequest model.
 */
@Fluent
public final class ChangeAllowanceRequest implements JsonSerializable<ChangeAllowanceRequest> {
    /*
     * The new total allowed widgets.
     */
    private Integer totalAllowed;

    /*
     * The reason for the change.
     */
    private String reason;

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

    /**
     * Get the totalAllowed property: The new total allowed widgets.
     * 
     * @return the totalAllowed value.
     */
    public Integer totalAllowed() {
        return this.totalAllowed;
    }

    /**
     * Set the totalAllowed property: The new total allowed widgets.
     * 
     * @param totalAllowed the totalAllowed value to set.
     * @return the ChangeAllowanceRequest object itself.
     */
    public ChangeAllowanceRequest withTotalAllowed(Integer totalAllowed) {
        this.totalAllowed = totalAllowed;
        return this;
    }

    /**
     * Get the reason property: The reason for the change.
     * 
     * @return the reason value.
     */
    public String reason() {
        return this.reason;
    }

    /**
     * Set the reason property: The reason for the change.
     * 
     * @param reason the reason value to set.
     * @return the ChangeAllowanceRequest object itself.
     */
    public ChangeAllowanceRequest withReason(String reason) {
        this.reason = reason;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeNumberField("totalAllowed", this.totalAllowed);
        jsonWriter.writeStringField("reason", this.reason);
        return jsonWriter.writeEndObject();
    }

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

                if ("totalAllowed".equals(fieldName)) {
                    deserializedChangeAllowanceRequest.totalAllowed = reader.getNullable(JsonReader::getInt);
                } else if ("reason".equals(fieldName)) {
                    deserializedChangeAllowanceRequest.reason = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedChangeAllowanceRequest;
        });
    }
}
