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

package tsptest.specialchars.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 Resource model.
 */
@Immutable
public final class Resource implements JsonSerializable<Resource> {
    /*
     * id
     */
    @Generated
    private final String id;

    /*
     * The aggregation function to be applied on the client metric. Allowed functions
     * - ‘percentage’ - for error metric , ‘avg’, ‘p50’, ‘p90’, ‘p95’, ‘p99’, ‘min’,
     * ‘max’ - for response_time_ms and latency metric, ‘avg’ - for requests_per_sec,
     * ‘count’ - for requests
     */
    @Generated
    private String aggregate;

    /*
     * The comparison operator. Supported types ‘>’, ‘<’
     */
    @Generated
    private String condition;

    /*
     * Request name for which the Pass fail criteria has to be applied
     */
    @Generated
    private String requestName;

    /*
     * The value to compare with the client metric. Allowed values - ‘error : [0.0 ,
     * 100.0] unit- % ’, response_time_ms and latency : any integer value unit- ms.
     */
    @Generated
    private Double value;

    /**
     * Creates an instance of Resource class.
     * 
     * @param id the id value to set.
     */
    @Generated
    private Resource(String id) {
        this.id = id;
    }

    /**
     * Get the id property: id.
     * 
     * @return the id value.
     */
    @Generated
    public String getId() {
        return this.id;
    }

    /**
     * Get the aggregate property: The aggregation function to be applied on the client metric. Allowed functions
     * - ‘percentage’ - for error metric , ‘avg’, ‘p50’, ‘p90’, ‘p95’, ‘p99’, ‘min’,
     * ‘max’ - for response_time_ms and latency metric, ‘avg’ - for requests_per_sec,
     * ‘count’ - for requests.
     * 
     * @return the aggregate value.
     */
    @Generated
    public String getAggregate() {
        return this.aggregate;
    }

    /**
     * Get the condition property: The comparison operator. Supported types ‘&gt;’, ‘&lt;’.
     * 
     * @return the condition value.
     */
    @Generated
    public String getCondition() {
        return this.condition;
    }

    /**
     * Get the requestName property: Request name for which the Pass fail criteria has to be applied.
     * 
     * @return the requestName value.
     */
    @Generated
    public String getRequestName() {
        return this.requestName;
    }

    /**
     * Get the value property: The value to compare with the client metric. Allowed values - ‘error : [0.0 ,
     * 100.0] unit- % ’, response_time_ms and latency : any integer value unit- ms.
     * 
     * @return the value value.
     */
    @Generated
    public Double getValue() {
        return this.value;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("id", this.id);
        jsonWriter.writeStringField("aggregate", this.aggregate);
        jsonWriter.writeStringField("condition", this.condition);
        jsonWriter.writeStringField("requestName", this.requestName);
        jsonWriter.writeNumberField("value", this.value);
        return jsonWriter.writeEndObject();
    }

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

                if ("id".equals(fieldName)) {
                    id = reader.getString();
                } else if ("aggregate".equals(fieldName)) {
                    aggregate = reader.getString();
                } else if ("condition".equals(fieldName)) {
                    condition = reader.getString();
                } else if ("requestName".equals(fieldName)) {
                    requestName = reader.getString();
                } else if ("value".equals(fieldName)) {
                    value = reader.getNullable(JsonReader::getDouble);
                } else {
                    reader.skipChildren();
                }
            }
            Resource deserializedResource = new Resource(id);
            deserializedResource.aggregate = aggregate;
            deserializedResource.condition = condition;
            deserializedResource.requestName = requestName;
            deserializedResource.value = value;

            return deserializedResource;
        });
    }
}
