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

package tsptest.naming.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 RunObjectLastErrorRenamed lastError;

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

    /**
     * Get the lastError property: The last_error property.
     * 
     * @return the lastError value.
     */
    @Generated
    public RunObjectLastErrorRenamed 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 -> {
            RunObjectLastErrorRenamed lastError = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

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