// 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 java.util.List;
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 text chunk with optional embedding and metadata.
 *
 * Chunks are created when chunking is enabled in {@code ExtractionConfig}. Each chunk
 * contains the text content, optional embedding vector (if embedding generation
 * is configured), and metadata about its position in the document.
 */
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonDeserialize(builder = Chunk.Builder.class)
public record Chunk(
    /**
     * The text content of this chunk.
     */
    @JsonProperty("content") String content,
    /**
     * Semantic structural classification of this chunk.
     *
     * Assigned by the heuristic classifier based on content patterns and
     * heading context. Defaults to {@code ChunkType.Unknown} when no rule matches.
     */
    @Nullable @JsonProperty("chunk_type") ChunkType chunkType,
    /**
     * Optional embedding vector for this chunk.
     *
     * Only populated when {@code EmbeddingConfig} is provided in chunking configuration.
     * The dimensionality depends on the chosen embedding model.
     */
    @Nullable @JsonProperty("embedding") List<Float> embedding,
    /**
     * Metadata about this chunk's position and properties.
     */
    @JsonProperty("metadata") ChunkMetadata metadata
) {
    public static Builder builder() {
        return new Builder();
    }

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

private String content = "";
        @JsonProperty("chunk_type")
        @Nullable private ChunkType chunkType = ChunkType.Unknown;
private List<Float> embedding = null;
private ChunkMetadata metadata = null;

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

        /** Sets the chunkType field. */
        @JsonProperty("chunk_type")
        public Builder withChunkType(final @Nullable ChunkType value) {
            this.chunkType = value;
            return this;
        }

        /** Sets the embedding field. */
        @JsonProperty("embedding")
        public Builder withEmbedding(final @Nullable List<Float> value) {
            this.embedding = value;
            return this;
        }

        /** Sets the metadata field. */
        @JsonProperty("metadata")
        public Builder withMetadata(final ChunkMetadata value) {
            this.metadata = value;
            return this;
        }

        /** Builds the Chunk instance. */
        public Chunk build() {
            return new Chunk(
                content,
                chunkType,
                embedding,
                metadata
            );
        }
    }
    // CPD-ON
}
