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

package azure.example.basic.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;

/**
 * The Model model.
 */
@Fluent
public final class Model implements JsonSerializable<Model> {
    /*
     * The int32Property property.
     */
    @Generated
    private Integer int32Property;

    /*
     * The float32Property property.
     */
    @Generated
    private Double float32Property;

    /*
     * The enumProperty property.
     */
    @Generated
    private Enum enumProperty;

    /**
     * Creates an instance of Model class.
     */
    @Generated
    public Model() {
    }

    /**
     * Get the int32Property property: The int32Property property.
     * 
     * @return the int32Property value.
     */
    @Generated
    public Integer getInt32Property() {
        return this.int32Property;
    }

    /**
     * Set the int32Property property: The int32Property property.
     * 
     * @param int32Property the int32Property value to set.
     * @return the Model object itself.
     */
    @Generated
    public Model setInt32Property(Integer int32Property) {
        this.int32Property = int32Property;
        return this;
    }

    /**
     * Get the float32Property property: The float32Property property.
     * 
     * @return the float32Property value.
     */
    @Generated
    public Double getFloat32Property() {
        return this.float32Property;
    }

    /**
     * Set the float32Property property: The float32Property property.
     * 
     * @param float32Property the float32Property value to set.
     * @return the Model object itself.
     */
    @Generated
    public Model setFloat32Property(Double float32Property) {
        this.float32Property = float32Property;
        return this;
    }

    /**
     * Get the enumProperty property: The enumProperty property.
     * 
     * @return the enumProperty value.
     */
    @Generated
    public Enum getEnumProperty() {
        return this.enumProperty;
    }

    /**
     * Set the enumProperty property: The enumProperty property.
     * 
     * @param enumProperty the enumProperty value to set.
     * @return the Model object itself.
     */
    @Generated
    public Model setEnumProperty(Enum enumProperty) {
        this.enumProperty = enumProperty;
        return this;
    }

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

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

                if ("int32Property".equals(fieldName)) {
                    deserializedModel.int32Property = reader.getNullable(JsonReader::getInt);
                } else if ("float32Property".equals(fieldName)) {
                    deserializedModel.float32Property = reader.getNullable(JsonReader::getDouble);
                } else if ("enumProperty".equals(fieldName)) {
                    deserializedModel.enumProperty = Enum.fromString(reader.getString());
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedModel;
        });
    }
}
