// 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.Immutable;
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;
import java.util.Objects;

/** Represents all of the state that defines and dictates the indexer's current execution. */
@Immutable
public final class IndexerCurrentState implements JsonSerializable<IndexerCurrentState> {
    /*
     * The mode the indexer is running in.
     */
    private IndexingMode mode;

    /*
     * Change tracking state used when indexing starts on all documents in the datasource.
     */
    private String allDocsInitialChangeTrackingState;

    /*
     * Change tracking state value when indexing finishes on all documents in the datasource.
     */
    private String allDocsFinalChangeTrackingState;

    /*
     * Change tracking state used when indexing starts on select, reset documents in the datasource.
     */
    private String resetDocsInitialChangeTrackingState;

    /*
     * Change tracking state value when indexing finishes on select, reset documents in the datasource.
     */
    private String resetDocsFinalChangeTrackingState;

    /*
     * The list of document keys that have been reset. The document key is the document's unique identifier for the
     * data in the search index. The indexer will prioritize selectively re-ingesting these keys.
     */
    private List<String> resetDocumentKeys;

    /*
     * The list of datasource document ids that have been reset. The datasource document id is the unique identifier
     * for the data in the datasource. The indexer will prioritize selectively re-ingesting these ids.
     */
    private List<String> resetDatasourceDocumentIds;

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

    /**
     * Get the mode property: The mode the indexer is running in.
     *
     * @return the mode value.
     */
    public IndexingMode getMode() {
        return this.mode;
    }

    /**
     * Get the allDocsInitialChangeTrackingState property: Change tracking state used when indexing starts on all
     * documents in the datasource.
     *
     * @return the allDocsInitialChangeTrackingState value.
     */
    public String getAllDocsInitialChangeTrackingState() {
        return this.allDocsInitialChangeTrackingState;
    }

    /**
     * Get the allDocsFinalChangeTrackingState property: Change tracking state value when indexing finishes on all
     * documents in the datasource.
     *
     * @return the allDocsFinalChangeTrackingState value.
     */
    public String getAllDocsFinalChangeTrackingState() {
        return this.allDocsFinalChangeTrackingState;
    }

    /**
     * Get the resetDocsInitialChangeTrackingState property: Change tracking state used when indexing starts on select,
     * reset documents in the datasource.
     *
     * @return the resetDocsInitialChangeTrackingState value.
     */
    public String getResetDocsInitialChangeTrackingState() {
        return this.resetDocsInitialChangeTrackingState;
    }

    /**
     * Get the resetDocsFinalChangeTrackingState property: Change tracking state value when indexing finishes on select,
     * reset documents in the datasource.
     *
     * @return the resetDocsFinalChangeTrackingState value.
     */
    public String getResetDocsFinalChangeTrackingState() {
        return this.resetDocsFinalChangeTrackingState;
    }

    /**
     * Get the resetDocumentKeys property: The list of document keys that have been reset. The document key is the
     * document's unique identifier for the data in the search index. The indexer will prioritize selectively
     * re-ingesting these keys.
     *
     * @return the resetDocumentKeys value.
     */
    public List<String> getResetDocumentKeys() {
        return this.resetDocumentKeys;
    }

    /**
     * Get the resetDatasourceDocumentIds property: The list of datasource document ids that have been reset. The
     * datasource document id is the unique identifier for the data in the datasource. The indexer will prioritize
     * selectively re-ingesting these ids.
     *
     * @return the resetDatasourceDocumentIds value.
     */
    public List<String> getResetDatasourceDocumentIds() {
        return this.resetDatasourceDocumentIds;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("mode", Objects.toString(this.mode, null));
        jsonWriter.writeStringField("allDocsInitialChangeTrackingState", this.allDocsInitialChangeTrackingState);
        jsonWriter.writeStringField("allDocsFinalChangeTrackingState", this.allDocsFinalChangeTrackingState);
        jsonWriter.writeStringField("resetDocsInitialChangeTrackingState", this.resetDocsInitialChangeTrackingState);
        jsonWriter.writeStringField("resetDocsFinalChangeTrackingState", this.resetDocsFinalChangeTrackingState);
        jsonWriter.writeArrayField(
                "resetDocumentKeys", this.resetDocumentKeys, (writer, element) -> writer.writeString(element));
        jsonWriter.writeArrayField(
                "resetDatasourceDocumentIds",
                this.resetDatasourceDocumentIds,
                (writer, element) -> writer.writeString(element));
        return jsonWriter.writeEndObject();
    }

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

                        if ("mode".equals(fieldName)) {
                            deserializedIndexerCurrentState.mode = IndexingMode.fromString(reader.getString());
                        } else if ("allDocsInitialChangeTrackingState".equals(fieldName)) {
                            deserializedIndexerCurrentState.allDocsInitialChangeTrackingState = reader.getString();
                        } else if ("allDocsFinalChangeTrackingState".equals(fieldName)) {
                            deserializedIndexerCurrentState.allDocsFinalChangeTrackingState = reader.getString();
                        } else if ("resetDocsInitialChangeTrackingState".equals(fieldName)) {
                            deserializedIndexerCurrentState.resetDocsInitialChangeTrackingState = reader.getString();
                        } else if ("resetDocsFinalChangeTrackingState".equals(fieldName)) {
                            deserializedIndexerCurrentState.resetDocsFinalChangeTrackingState = reader.getString();
                        } else if ("resetDocumentKeys".equals(fieldName)) {
                            List<String> resetDocumentKeys = reader.readArray(reader1 -> reader1.getString());
                            deserializedIndexerCurrentState.resetDocumentKeys = resetDocumentKeys;
                        } else if ("resetDatasourceDocumentIds".equals(fieldName)) {
                            List<String> resetDatasourceDocumentIds = reader.readArray(reader1 -> reader1.getString());
                            deserializedIndexerCurrentState.resetDatasourceDocumentIds = resetDatasourceDocumentIds;
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedIndexerCurrentState;
                });
    }
}
