// 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.indexes.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;

/**
 * Describes the title, content, and keywords fields to be used for semantic ranking, captions, highlights, and answers.
 */
@Fluent
public final class PrioritizedFields implements JsonSerializable<PrioritizedFields> {
    /*
     * Defines the title field to be used for semantic ranking, captions, highlights, and answers. If you don't have a
     * title field in your index, leave this blank.
     */
    private SemanticField titleField;

    /*
     * Defines the content fields to be used for semantic ranking, captions, highlights, and answers. For the best
     * result, the selected fields should contain text in natural language form. The order of the fields in the array
     * represents their priority. Fields with lower priority may get truncated if the content is long.
     */
    private List<SemanticField> prioritizedContentFields;

    /*
     * Defines the keyword fields to be used for semantic ranking, captions, highlights, and answers. For the best
     * result, the selected fields should contain a list of keywords. The order of the fields in the array represents
     * their priority. Fields with lower priority may get truncated if the content is long.
     */
    private List<SemanticField> prioritizedKeywordsFields;

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

    /**
     * Get the titleField property: Defines the title field to be used for semantic ranking, captions, highlights, and
     * answers. If you don't have a title field in your index, leave this blank.
     *
     * @return the titleField value.
     */
    public SemanticField getTitleField() {
        return this.titleField;
    }

    /**
     * Set the titleField property: Defines the title field to be used for semantic ranking, captions, highlights, and
     * answers. If you don't have a title field in your index, leave this blank.
     *
     * @param titleField the titleField value to set.
     * @return the PrioritizedFields object itself.
     */
    public PrioritizedFields setTitleField(SemanticField titleField) {
        this.titleField = titleField;
        return this;
    }

    /**
     * Get the prioritizedContentFields property: Defines the content fields to be used for semantic ranking, captions,
     * highlights, and answers. For the best result, the selected fields should contain text in natural language form.
     * The order of the fields in the array represents their priority. Fields with lower priority may get truncated if
     * the content is long.
     *
     * @return the prioritizedContentFields value.
     */
    public List<SemanticField> getPrioritizedContentFields() {
        return this.prioritizedContentFields;
    }

    /**
     * Set the prioritizedContentFields property: Defines the content fields to be used for semantic ranking, captions,
     * highlights, and answers. For the best result, the selected fields should contain text in natural language form.
     * The order of the fields in the array represents their priority. Fields with lower priority may get truncated if
     * the content is long.
     *
     * @param prioritizedContentFields the prioritizedContentFields value to set.
     * @return the PrioritizedFields object itself.
     */
    public PrioritizedFields setPrioritizedContentFields(List<SemanticField> prioritizedContentFields) {
        this.prioritizedContentFields = prioritizedContentFields;
        return this;
    }

    /**
     * Get the prioritizedKeywordsFields property: Defines the keyword fields to be used for semantic ranking, captions,
     * highlights, and answers. For the best result, the selected fields should contain a list of keywords. The order of
     * the fields in the array represents their priority. Fields with lower priority may get truncated if the content is
     * long.
     *
     * @return the prioritizedKeywordsFields value.
     */
    public List<SemanticField> getPrioritizedKeywordsFields() {
        return this.prioritizedKeywordsFields;
    }

    /**
     * Set the prioritizedKeywordsFields property: Defines the keyword fields to be used for semantic ranking, captions,
     * highlights, and answers. For the best result, the selected fields should contain a list of keywords. The order of
     * the fields in the array represents their priority. Fields with lower priority may get truncated if the content is
     * long.
     *
     * @param prioritizedKeywordsFields the prioritizedKeywordsFields value to set.
     * @return the PrioritizedFields object itself.
     */
    public PrioritizedFields setPrioritizedKeywordsFields(List<SemanticField> prioritizedKeywordsFields) {
        this.prioritizedKeywordsFields = prioritizedKeywordsFields;
        return this;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeJsonField("titleField", this.titleField);
        jsonWriter.writeArrayField(
                "prioritizedContentFields",
                this.prioritizedContentFields,
                (writer, element) -> writer.writeJson(element));
        jsonWriter.writeArrayField(
                "prioritizedKeywordsFields",
                this.prioritizedKeywordsFields,
                (writer, element) -> writer.writeJson(element));
        return jsonWriter.writeEndObject();
    }

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

                        if ("titleField".equals(fieldName)) {
                            deserializedPrioritizedFields.titleField = SemanticField.fromJson(reader);
                        } else if ("prioritizedContentFields".equals(fieldName)) {
                            List<SemanticField> prioritizedContentFields =
                                    reader.readArray(reader1 -> SemanticField.fromJson(reader1));
                            deserializedPrioritizedFields.prioritizedContentFields = prioritizedContentFields;
                        } else if ("prioritizedKeywordsFields".equals(fieldName)) {
                            List<SemanticField> prioritizedKeywordsFields =
                                    reader.readArray(reader1 -> SemanticField.fromJson(reader1));
                            deserializedPrioritizedFields.prioritizedKeywordsFields = prioritizedKeywordsFields;
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedPrioritizedFields;
                });
    }
}
