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

com.azure.ai.metricsadvisor.implementation.models.CommentFeedback Maven / Gradle / Ivy

The newest version!
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.ai.metricsadvisor.implementation.models;

import com.azure.ai.metricsadvisor.models.FeedbackType;
import com.azure.core.annotation.Fluent;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.UUID;

/**
 * The CommentFeedback model.
 */
@Fluent
public final class CommentFeedback extends MetricFeedback {
    /*
     * the start timestamp of feedback time range
     */
    private OffsetDateTime startTime;

    /*
     * the end timestamp of feedback time range, when equals to startTime means only one timestamp
     */
    private OffsetDateTime endTime;

    /*
     * The value property.
     */
    private CommentFeedbackValue value;

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

    /**
     * Get the startTime property: the start timestamp of feedback time range.
     * 
     * @return the startTime value.
     */
    public OffsetDateTime getStartTime() {
        return this.startTime;
    }

    /**
     * Set the startTime property: the start timestamp of feedback time range.
     * 
     * @param startTime the startTime value to set.
     * @return the CommentFeedback object itself.
     */
    public CommentFeedback setStartTime(OffsetDateTime startTime) {
        this.startTime = startTime;
        return this;
    }

    /**
     * Get the endTime property: the end timestamp of feedback time range, when equals to startTime means only one
     * timestamp.
     * 
     * @return the endTime value.
     */
    public OffsetDateTime getEndTime() {
        return this.endTime;
    }

    /**
     * Set the endTime property: the end timestamp of feedback time range, when equals to startTime means only one
     * timestamp.
     * 
     * @param endTime the endTime value to set.
     * @return the CommentFeedback object itself.
     */
    public CommentFeedback setEndTime(OffsetDateTime endTime) {
        this.endTime = endTime;
        return this;
    }

    /**
     * Get the value property: The value property.
     * 
     * @return the value value.
     */
    public CommentFeedbackValue getValue() {
        return this.value;
    }

    /**
     * Set the value property: The value property.
     * 
     * @param value the value value to set.
     * @return the CommentFeedback object itself.
     */
    public CommentFeedback setValue(CommentFeedbackValue value) {
        this.value = value;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CommentFeedback setMetricId(UUID metricId) {
        super.setMetricId(metricId);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CommentFeedback setDimensionFilter(FeedbackDimensionFilter dimensionFilter) {
        super.setDimensionFilter(dimensionFilter);
        return this;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("feedbackType",
            FeedbackType.COMMENT == null ? null : FeedbackType.COMMENT.toString());
        jsonWriter.writeStringField("metricId", Objects.toString(getMetricId(), null));
        jsonWriter.writeJsonField("dimensionFilter", getDimensionFilter());
        jsonWriter.writeJsonField("value", this.value);
        jsonWriter.writeStringField("startTime",
            this.startTime == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.startTime));
        jsonWriter.writeStringField("endTime",
            this.endTime == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.endTime));
        return jsonWriter.writeEndObject();
    }

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

                if ("feedbackType".equals(fieldName)) {
                    String feedbackType = reader.getString();
                    if (!"Comment".equals(feedbackType)) {
                        throw new IllegalStateException(
                            "'feedbackType' was expected to be non-null and equal to 'Comment'. The found 'feedbackType' was '"
                                + feedbackType + "'.");
                    }
                } else if ("metricId".equals(fieldName)) {
                    deserializedCommentFeedback
                        .setMetricId(reader.getNullable(nonNullReader -> UUID.fromString(nonNullReader.getString())));
                } else if ("dimensionFilter".equals(fieldName)) {
                    deserializedCommentFeedback.setDimensionFilter(FeedbackDimensionFilter.fromJson(reader));
                } else if ("feedbackId".equals(fieldName)) {
                    deserializedCommentFeedback
                        .setFeedbackId(reader.getNullable(nonNullReader -> UUID.fromString(nonNullReader.getString())));
                } else if ("createdTime".equals(fieldName)) {
                    deserializedCommentFeedback.setCreatedTime(
                        reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())));
                } else if ("userPrincipal".equals(fieldName)) {
                    deserializedCommentFeedback.setUserPrincipal(reader.getString());
                } else if ("value".equals(fieldName)) {
                    deserializedCommentFeedback.value = CommentFeedbackValue.fromJson(reader);
                } else if ("startTime".equals(fieldName)) {
                    deserializedCommentFeedback.startTime
                        = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()));
                } else if ("endTime".equals(fieldName)) {
                    deserializedCommentFeedback.endTime
                        = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString()));
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedCommentFeedback;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy