// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package com.azure.search.documents.models;

import com.azure.core.annotation.Fluent;
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.List;

/** The query parameters for vector and hybrid search queries. */
@Fluent
public final class SearchQueryVector implements JsonSerializable<SearchQueryVector> {
    /*
     * The vector representation of a search query.
     */
    private List<Float> value;

    /*
     * Number of nearest neighbors to return as top hits.
     */
    private Integer kNearestNeighborsCount;

    /*
     * Vector Fields of type Collection(Edm.Single) to be included in the vector searched.
     */
    private String fields;

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

    /**
     * Get the value property: The vector representation of a search query.
     *
     * @return the value value.
     */
    public List<Float> getValue() {
        return this.value;
    }

    /**
     * Set the value property: The vector representation of a search query.
     *
     * @param value the value value to set.
     * @return the SearchQueryVector object itself.
     */
    public SearchQueryVector setValue(List<Float> value) {
        this.value = value;
        return this;
    }

    /**
     * Get the kNearestNeighborsCount property: Number of nearest neighbors to return as top hits.
     *
     * @return the kNearestNeighborsCount value.
     */
    public Integer getKNearestNeighborsCount() {
        return this.kNearestNeighborsCount;
    }

    /**
     * Set the kNearestNeighborsCount property: Number of nearest neighbors to return as top hits.
     *
     * @param kNearestNeighborsCount the kNearestNeighborsCount value to set.
     * @return the SearchQueryVector object itself.
     */
    public SearchQueryVector setKNearestNeighborsCount(Integer kNearestNeighborsCount) {
        this.kNearestNeighborsCount = kNearestNeighborsCount;
        return this;
    }

    /**
     * Get the fields property: Vector Fields of type Collection(Edm.Single) to be included in the vector searched.
     *
     * @return the fields value.
     */
    public String getFields() {
        return this.fields;
    }

    /**
     * Set the fields property: Vector Fields of type Collection(Edm.Single) to be included in the vector searched.
     *
     * @param fields the fields value to set.
     * @return the SearchQueryVector object itself.
     */
    public SearchQueryVector setFields(String fields) {
        this.fields = fields;
        return this;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeFloat(element));
        jsonWriter.writeNumberField("k", this.kNearestNeighborsCount);
        jsonWriter.writeStringField("fields", this.fields);
        return jsonWriter.writeEndObject();
    }

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

                        if ("value".equals(fieldName)) {
                            List<Float> value = reader.readArray(reader1 -> reader1.getFloat());
                            deserializedSearchQueryVector.value = value;
                        } else if ("k".equals(fieldName)) {
                            deserializedSearchQueryVector.kNearestNeighborsCount =
                                    reader.getNullable(JsonReader::getInt);
                        } else if ("fields".equals(fieldName)) {
                            deserializedSearchQueryVector.fields = reader.getString();
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedSearchQueryVector;
                });
    }
}
