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

/** The SearchIndexerLimits model. */
@Immutable
public final class SearchIndexerLimits implements JsonSerializable<SearchIndexerLimits> {
    /*
     * The maximum duration that the indexer is permitted to run for one execution.
     */
    private Duration maxRunTime;

    /*
     * The maximum size of a document, in bytes, which will be considered valid for indexing.
     */
    private Long maxDocumentExtractionSize;

    /*
     * The maximum number of characters that will be extracted from a document picked up for indexing.
     */
    private Long maxDocumentContentCharactersToExtract;

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

    /**
     * Get the maxRunTime property: The maximum duration that the indexer is permitted to run for one execution.
     *
     * @return the maxRunTime value.
     */
    public Duration getMaxRunTime() {
        return this.maxRunTime;
    }

    /**
     * Get the maxDocumentExtractionSize property: The maximum size of a document, in bytes, which will be considered
     * valid for indexing.
     *
     * @return the maxDocumentExtractionSize value.
     */
    public Long getMaxDocumentExtractionSize() {
        return this.maxDocumentExtractionSize;
    }

    /**
     * Get the maxDocumentContentCharactersToExtract property: The maximum number of characters that will be extracted
     * from a document picked up for indexing.
     *
     * @return the maxDocumentContentCharactersToExtract value.
     */
    public Long getMaxDocumentContentCharactersToExtract() {
        return this.maxDocumentContentCharactersToExtract;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("maxRunTime", Objects.toString(this.maxRunTime, null));
        jsonWriter.writeNumberField("maxDocumentExtractionSize", this.maxDocumentExtractionSize);
        jsonWriter.writeNumberField(
                "maxDocumentContentCharactersToExtract", this.maxDocumentContentCharactersToExtract);
        return jsonWriter.writeEndObject();
    }

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

                        if ("maxRunTime".equals(fieldName)) {
                            deserializedSearchIndexerLimits.maxRunTime =
                                    reader.getNullable(nonNullReader -> Duration.parse(nonNullReader.getString()));
                        } else if ("maxDocumentExtractionSize".equals(fieldName)) {
                            deserializedSearchIndexerLimits.maxDocumentExtractionSize =
                                    reader.getNullable(JsonReader::getLong);
                        } else if ("maxDocumentContentCharactersToExtract".equals(fieldName)) {
                            deserializedSearchIndexerLimits.maxDocumentContentCharactersToExtract =
                                    reader.getNullable(JsonReader::getLong);
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedSearchIndexerLimits;
                });
    }
}
