// This file is auto-generated by alef — DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
// To regenerate: alef generate
// To verify freshness: alef verify --exit-code
// Issues & docs: https://github.com/kreuzberg-dev/alef
package dev.kreuzberg;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import org.jspecify.annotations.Nullable;

/**
 * A single backend stage in the OCR pipeline.
 */
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonDeserialize(builder = OcrPipelineStage.Builder.class)
public record OcrPipelineStage(
    /**
     * Backend name: "tesseract", "paddleocr", "easyocr", or a custom registered name.
     */
    @JsonProperty("backend") String backend,
    /**
     * Priority weight (higher = tried first). Stages are sorted by priority descending.
     */
    @Nullable @JsonProperty("priority") Integer priority,
    /**
     * Language override for this stage (null = use parent OcrConfig.language).
     */
    @Nullable @JsonProperty("language") String language,
    /**
     * Tesseract-specific config override for this stage.
     */
    @Nullable @JsonProperty("tesseract_config") TesseractConfig tesseractConfig,
    /**
     * PaddleOCR-specific config for this stage.
     */
    @Nullable @JsonProperty("paddle_ocr_config") JsonNode paddleOcrConfig,
    /**
     * VLM config override for this pipeline stage.
     */
    @Nullable @JsonProperty("vlm_config") LlmConfig vlmConfig,
    /**
     * Arbitrary per-call options passed through to the backend unchanged.
     *
     * Backends that support runtime tuning (mode switching, preprocessing
     * flags, inference parameters, etc.) read this value and deserialize
     * the keys they care about. Keys unknown to the backend are silently
     * ignored, so options from different backends can coexist in the same
     * config without conflict.
     *
     * Example (custom backend):
     * {@code }{@code json}
     * { "mode": "fast", "enable_layout": true }
     *
     */
    @Nullable @JsonProperty("backend_options") JsonNode backendOptions
) {
    public static Builder builder() {
        return new Builder();
    }

    // CPD-OFF
    @JsonPOJOBuilder(withPrefix = "with", buildMethodName = "build")
    public static final class Builder {

private String backend = "";
private Integer priority = null;
private String language = null;
        @JsonProperty("tesseract_config")
        @Nullable private TesseractConfig tesseractConfig = null;
        @JsonProperty("paddle_ocr_config")
private JsonNode paddleOcrConfig = null;
        @JsonProperty("vlm_config")
        @Nullable private LlmConfig vlmConfig = null;
        @JsonProperty("backend_options")
private JsonNode backendOptions = null;

        /** Sets the backend field. */
        @JsonProperty("backend")
        public Builder withBackend(final String value) {
            this.backend = value;
            return this;
        }

        /** Sets the priority field. */
        @JsonProperty("priority")
        public Builder withPriority(final @Nullable Integer value) {
            this.priority = value;
            return this;
        }

        /** Sets the language field. */
        @JsonProperty("language")
        public Builder withLanguage(final @Nullable String value) {
            this.language = value;
            return this;
        }

        /** Sets the tesseractConfig field. */
        @JsonProperty("tesseract_config")
        public Builder withTesseractConfig(final @Nullable TesseractConfig value) {
            this.tesseractConfig = value;
            return this;
        }

        /** Sets the paddleOcrConfig field. */
        @JsonProperty("paddle_ocr_config")
        public Builder withPaddleOcrConfig(final @Nullable JsonNode value) {
            this.paddleOcrConfig = value;
            return this;
        }

        /** Sets the vlmConfig field. */
        @JsonProperty("vlm_config")
        public Builder withVlmConfig(final @Nullable LlmConfig value) {
            this.vlmConfig = value;
            return this;
        }

        /** Sets the backendOptions field. */
        @JsonProperty("backend_options")
        public Builder withBackendOptions(final @Nullable JsonNode value) {
            this.backendOptions = value;
            return this;
        }

        /** Builds the OcrPipelineStage instance. */
        public OcrPipelineStage build() {
            return new OcrPipelineStage(
                backend,
                priority,
                language,
                tesseractConfig,
                paddleOcrConfig,
                vlmConfig,
                backendOptions
            );
        }
    }
    // CPD-ON
}
