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

package tsptest.namingjavaparser.models;

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
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 RunObject model.
 */
@Immutable
public final class RunObject implements JsonSerializable<RunObject> {
    /*
     * The last_error property.
     */
    @Generated
    private final RunObjectLastError1 lastError;

    /**
     * Creates an instance of RunObject class.
     * 
     * @param lastError the lastError value to set.
     */
    @Generated
    private RunObject(RunObjectLastError1 lastError) {
        this.lastError = lastError;
    }

    /**
     * Get the lastError property: The last_error property.
     * 
     * @return the lastError value.
     */
    @Generated
    public RunObjectLastError1 getLastError() {
        return this.lastError;
    }

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

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

                if ("last_error".equals(fieldName)) {
                    lastError = RunObjectLastError1.fromJson(reader);
                } else {
                    reader.skipChildren();
                }
            }
            return new RunObject(lastError);
        });
    }
}
