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

com.azure.resourcemanager.orbital.fluent.models.OperationResultInner 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.orbital.fluent.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.CoreUtils;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import com.azure.resourcemanager.orbital.models.OperationResultErrorProperties;
import com.azure.resourcemanager.orbital.models.Status;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.List;

/**
 * Operation Result Entity.
 */
@Fluent
public final class OperationResultInner implements JsonSerializable {
    /*
     * ID of the resource.
     */
    private String id;

    /*
     * Name of the resource.
     */
    private String name;

    /*
     * The status of operation.
     */
    private Status status;

    /*
     * The operation start time (ISO 8601 UTC standard).
     */
    private OffsetDateTime startTime;

    /*
     * The operation end time (ISO 8601 UTC standard).
     */
    private OffsetDateTime endTime;

    /*
     * Percentage completed.
     */
    private Double percentComplete;

    /*
     * A list of results when the operation returns multiple results.
     */
    private List value;

    /*
     * The URL to get the next set of results.
     */
    private String nextLink;

    /*
     * Operation result properties.
     */
    private Object properties;

    /*
     * Operation result error properties.
     */
    private OperationResultErrorProperties error;

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

    /**
     * Get the id property: ID of the resource.
     * 
     * @return the id value.
     */
    public String id() {
        return this.id;
    }

    /**
     * Get the name property: Name of the resource.
     * 
     * @return the name value.
     */
    public String name() {
        return this.name;
    }

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

    /**
     * Get the startTime property: The operation start time (ISO 8601 UTC standard).
     * 
     * @return the startTime value.
     */
    public OffsetDateTime startTime() {
        return this.startTime;
    }

    /**
     * Get the endTime property: The operation end time (ISO 8601 UTC standard).
     * 
     * @return the endTime value.
     */
    public OffsetDateTime endTime() {
        return this.endTime;
    }

    /**
     * Get the percentComplete property: Percentage completed.
     * 
     * @return the percentComplete value.
     */
    public Double percentComplete() {
        return this.percentComplete;
    }

    /**
     * Get the value property: A list of results when the operation returns multiple results.
     * 
     * @return the value value.
     */
    public List value() {
        return this.value;
    }

    /**
     * Get the nextLink property: The URL to get the next set of results.
     * 
     * @return the nextLink value.
     */
    public String nextLink() {
        return this.nextLink;
    }

    /**
     * Get the properties property: Operation result properties.
     * 
     * @return the properties value.
     */
    public Object properties() {
        return this.properties;
    }

    /**
     * Set the properties property: Operation result properties.
     * 
     * @param properties the properties value to set.
     * @return the OperationResultInner object itself.
     */
    public OperationResultInner withProperties(Object properties) {
        this.properties = properties;
        return this;
    }

    /**
     * Get the error property: Operation result error properties.
     * 
     * @return the error value.
     */
    public OperationResultErrorProperties error() {
        return this.error;
    }

    /**
     * Set the error property: Operation result error properties.
     * 
     * @param error the error value to set.
     * @return the OperationResultInner object itself.
     */
    public OperationResultInner withError(OperationResultErrorProperties error) {
        this.error = error;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (error() != null) {
            error().validate();
        }
    }

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

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

                if ("id".equals(fieldName)) {
                    deserializedOperationResultInner.id = reader.getString();
                } else if ("name".equals(fieldName)) {
                    deserializedOperationResultInner.name = reader.getString();
                } else if ("status".equals(fieldName)) {
                    deserializedOperationResultInner.status = Status.fromString(reader.getString());
                } else if ("startTime".equals(fieldName)) {
                    deserializedOperationResultInner.startTime = reader
                        .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
                } else if ("endTime".equals(fieldName)) {
                    deserializedOperationResultInner.endTime = reader
                        .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
                } else if ("percentComplete".equals(fieldName)) {
                    deserializedOperationResultInner.percentComplete = reader.getNullable(JsonReader::getDouble);
                } else if ("value".equals(fieldName)) {
                    List value = reader.readArray(reader1 -> reader1.readUntyped());
                    deserializedOperationResultInner.value = value;
                } else if ("nextLink".equals(fieldName)) {
                    deserializedOperationResultInner.nextLink = reader.getString();
                } else if ("properties".equals(fieldName)) {
                    deserializedOperationResultInner.properties = reader.readUntyped();
                } else if ("error".equals(fieldName)) {
                    deserializedOperationResultInner.error = OperationResultErrorProperties.fromJson(reader);
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedOperationResultInner;
        });
    }
}