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

package azure.resourcemanager.operationtemplates.fluent.models;

import com.azure.core.annotation.Immutable;
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;

/**
 * The ChangeAllowanceResult model.
 */
@Immutable
public final class ChangeAllowanceResultInner implements JsonSerializable<ChangeAllowanceResultInner> {
    /*
     * The new total allowed widgets.
     */
    private int totalAllowed;

    /*
     * The status of the change.
     */
    private String status;

    /**
     * Creates an instance of ChangeAllowanceResultInner class.
     */
    private ChangeAllowanceResultInner() {
    }

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

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

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (status() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property status in model ChangeAllowanceResultInner"));
        }
    }

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

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

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

                if ("totalAllowed".equals(fieldName)) {
                    deserializedChangeAllowanceResultInner.totalAllowed = reader.getInt();
                } else if ("status".equals(fieldName)) {
                    deserializedChangeAllowanceResultInner.status = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedChangeAllowanceResultInner;
        });
    }
}
