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

package tsptest.longrunning.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;
import java.util.Map;

/**
 * The JobData model.
 */
@Fluent
public final class JobData implements JsonSerializable<JobData> {
    /*
     * The configuration property.
     */
    @Generated
    private String configuration;

    /*
     * The nullableFloatDict property.
     */
    @Generated
    private final Map<String, Double> nullableFloatDict;

    /**
     * Creates an instance of JobData class.
     * 
     * @param nullableFloatDict the nullableFloatDict value to set.
     */
    @Generated
    public JobData(Map<String, Double> nullableFloatDict) {
        this.nullableFloatDict = nullableFloatDict;
    }

    /**
     * Get the configuration property: The configuration property.
     * 
     * @return the configuration value.
     */
    @Generated
    public String getConfiguration() {
        return this.configuration;
    }

    /**
     * Set the configuration property: The configuration property.
     * 
     * @param configuration the configuration value to set.
     * @return the JobData object itself.
     */
    @Generated
    public JobData setConfiguration(String configuration) {
        this.configuration = configuration;
        return this;
    }

    /**
     * Get the nullableFloatDict property: The nullableFloatDict property.
     * 
     * @return the nullableFloatDict value.
     */
    @Generated
    public Map<String, Double> getNullableFloatDict() {
        return this.nullableFloatDict;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeMapField("nullableFloatDict", this.nullableFloatDict,
            (writer, element) -> writer.writeNumber(element));
        jsonWriter.writeStringField("configuration", this.configuration);
        return jsonWriter.writeEndObject();
    }

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

                if ("nullableFloatDict".equals(fieldName)) {
                    nullableFloatDict = reader.readMap(reader1 -> reader1.getNullable(JsonReader::getDouble));
                } else if ("configuration".equals(fieldName)) {
                    configuration = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }
            JobData deserializedJobData = new JobData(nullableFloatDict);
            deserializedJobData.configuration = configuration;

            return deserializedJobData;
        });
    }
}
