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

com.azure.resourcemanager.databoxedge.models.OrderStatus 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.databoxedge.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.CoreUtils;
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;
import java.time.OffsetDateTime;
import java.util.Map;

/**
 * Represents a single status change.
 */
@Fluent
public final class OrderStatus implements JsonSerializable {
    /*
     * Status of the order as per the allowed status types.
     */
    private OrderState status;

    /*
     * Time of status update.
     */
    private OffsetDateTime updateDateTime;

    /*
     * Comments related to this status change.
     */
    private String comments;

    /*
     * Dictionary to hold generic information which is not stored
     * by the already existing properties
     */
    private Map additionalOrderDetails;

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

    /**
     * Get the status property: Status of the order as per the allowed status types.
     * 
     * @return the status value.
     */
    public OrderState status() {
        return this.status;
    }

    /**
     * Set the status property: Status of the order as per the allowed status types.
     * 
     * @param status the status value to set.
     * @return the OrderStatus object itself.
     */
    public OrderStatus withStatus(OrderState status) {
        this.status = status;
        return this;
    }

    /**
     * Get the updateDateTime property: Time of status update.
     * 
     * @return the updateDateTime value.
     */
    public OffsetDateTime updateDateTime() {
        return this.updateDateTime;
    }

    /**
     * Get the comments property: Comments related to this status change.
     * 
     * @return the comments value.
     */
    public String comments() {
        return this.comments;
    }

    /**
     * Set the comments property: Comments related to this status change.
     * 
     * @param comments the comments value to set.
     * @return the OrderStatus object itself.
     */
    public OrderStatus withComments(String comments) {
        this.comments = comments;
        return this;
    }

    /**
     * Get the additionalOrderDetails property: Dictionary to hold generic information which is not stored
     * by the already existing properties.
     * 
     * @return the additionalOrderDetails value.
     */
    public Map additionalOrderDetails() {
        return this.additionalOrderDetails;
    }

    /**
     * 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 OrderStatus"));
        }
    }

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("status", this.status == null ? null : this.status.toString());
        jsonWriter.writeStringField("comments", this.comments);
        return jsonWriter.writeEndObject();
    }

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

                if ("status".equals(fieldName)) {
                    deserializedOrderStatus.status = OrderState.fromString(reader.getString());
                } else if ("updateDateTime".equals(fieldName)) {
                    deserializedOrderStatus.updateDateTime = reader
                        .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
                } else if ("comments".equals(fieldName)) {
                    deserializedOrderStatus.comments = reader.getString();
                } else if ("additionalOrderDetails".equals(fieldName)) {
                    Map additionalOrderDetails = reader.readMap(reader1 -> reader1.getString());
                    deserializedOrderStatus.additionalOrderDetails = additionalOrderDetails;
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedOrderStatus;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy