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

package azure.clientgenerator.core.clientdefaultvalue.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.annotation.Generated;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
 * Model with client default values on properties.
 */
@Fluent
public final class ModelWithDefaultValues implements JsonSerializable<ModelWithDefaultValues> {
    /*
     * Name property with no default value.
     */
    @Generated
    private final String name;

    /*
     * Timeout property with client default value of 30.
     */
    @Generated
    private Integer timeout;

    /*
     * Tier property with client default value of 'standard'.
     */
    @Generated
    private String tier;

    /*
     * Retry property with client default value of true.
     */
    @Generated
    private Boolean retry;

    /**
     * Creates an instance of ModelWithDefaultValues class.
     * 
     * @param name the name value to set.
     */
    @Generated
    public ModelWithDefaultValues(String name) {
        this.name = name;
    }

    /**
     * Get the name property: Name property with no default value.
     * 
     * @return the name value.
     */
    @Generated
    public String getName() {
        return this.name;
    }

    /**
     * Get the timeout property: Timeout property with client default value of 30.
     * 
     * @return the timeout value.
     */
    @Generated
    public Integer getTimeout() {
        return this.timeout;
    }

    /**
     * Set the timeout property: Timeout property with client default value of 30.
     * 
     * @param timeout the timeout value to set.
     * @return the ModelWithDefaultValues object itself.
     */
    @Generated
    public ModelWithDefaultValues setTimeout(Integer timeout) {
        this.timeout = timeout;
        return this;
    }

    /**
     * Get the tier property: Tier property with client default value of 'standard'.
     * 
     * @return the tier value.
     */
    @Generated
    public String getTier() {
        return this.tier;
    }

    /**
     * Set the tier property: Tier property with client default value of 'standard'.
     * 
     * @param tier the tier value to set.
     * @return the ModelWithDefaultValues object itself.
     */
    @Generated
    public ModelWithDefaultValues setTier(String tier) {
        this.tier = tier;
        return this;
    }

    /**
     * Get the retry property: Retry property with client default value of true.
     * 
     * @return the retry value.
     */
    @Generated
    public Boolean isRetry() {
        return this.retry;
    }

    /**
     * Set the retry property: Retry property with client default value of true.
     * 
     * @param retry the retry value to set.
     * @return the ModelWithDefaultValues object itself.
     */
    @Generated
    public ModelWithDefaultValues setRetry(Boolean retry) {
        this.retry = retry;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("name", this.name);
        jsonWriter.writeNumberField("timeout", this.timeout);
        jsonWriter.writeStringField("tier", this.tier);
        jsonWriter.writeBooleanField("retry", this.retry);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of ModelWithDefaultValues from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of ModelWithDefaultValues 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 ModelWithDefaultValues.
     */
    @Generated
    public static ModelWithDefaultValues fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String name = null;
            Integer timeout = null;
            String tier = null;
            Boolean retry = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("name".equals(fieldName)) {
                    name = reader.getString();
                } else if ("timeout".equals(fieldName)) {
                    timeout = reader.getNullable(JsonReader::getInt);
                } else if ("tier".equals(fieldName)) {
                    tier = reader.getString();
                } else if ("retry".equals(fieldName)) {
                    retry = reader.getNullable(JsonReader::getBoolean);
                } else {
                    reader.skipChildren();
                }
            }
            ModelWithDefaultValues deserializedModelWithDefaultValues = new ModelWithDefaultValues(name);
            deserializedModelWithDefaultValues.timeout = timeout;
            deserializedModelWithDefaultValues.tier = tier;
            deserializedModelWithDefaultValues.retry = retry;

            return deserializedModelWithDefaultValues;
        });
    }
}
