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

/** Defines parameters for a search index that influence semantic capabilities. */
@Fluent
public final class SemanticSettings implements JsonSerializable<SemanticSettings> {
    /*
     * Allows you to set the name of a default semantic configuration in your index, making it optional to pass it on
     * as a query parameter every time.
     */
    private String defaultConfiguration;

    /*
     * The semantic configurations for the index.
     */
    private List<SemanticConfiguration> configurations;

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

    /**
     * Get the defaultConfiguration property: Allows you to set the name of a default semantic configuration in your
     * index, making it optional to pass it on as a query parameter every time.
     *
     * @return the defaultConfiguration value.
     */
    public String getDefaultConfiguration() {
        return this.defaultConfiguration;
    }

    /**
     * Set the defaultConfiguration property: Allows you to set the name of a default semantic configuration in your
     * index, making it optional to pass it on as a query parameter every time.
     *
     * @param defaultConfiguration the defaultConfiguration value to set.
     * @return the SemanticSettings object itself.
     */
    public SemanticSettings setDefaultConfiguration(String defaultConfiguration) {
        this.defaultConfiguration = defaultConfiguration;
        return this;
    }

    /**
     * Get the configurations property: The semantic configurations for the index.
     *
     * @return the configurations value.
     */
    public List<SemanticConfiguration> getConfigurations() {
        return this.configurations;
    }

    /**
     * Set the configurations property: The semantic configurations for the index.
     *
     * @param configurations the configurations value to set.
     * @return the SemanticSettings object itself.
     */
    public SemanticSettings setConfigurations(List<SemanticConfiguration> configurations) {
        this.configurations = configurations;
        return this;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("defaultConfiguration", this.defaultConfiguration);
        jsonWriter.writeArrayField(
                "configurations", this.configurations, (writer, element) -> writer.writeJson(element));
        return jsonWriter.writeEndObject();
    }

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

                        if ("defaultConfiguration".equals(fieldName)) {
                            deserializedSemanticSettings.defaultConfiguration = reader.getString();
                        } else if ("configurations".equals(fieldName)) {
                            List<SemanticConfiguration> configurations =
                                    reader.readArray(reader1 -> SemanticConfiguration.fromJson(reader1));
                            deserializedSemanticSettings.configurations = configurations;
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedSemanticSettings;
                });
    }
}
