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

/**
 * Token usage and cost data for a single LLM call made during extraction.
 *
 * Populated when VLM OCR, structured extraction, or LLM-based embeddings
 * are used. Multiple entries may be present when multiple LLM calls occur
 * within one extraction (e.g. VLM OCR + structured extraction).
 */
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonDeserialize(builder = LlmUsage.Builder.class)
public record LlmUsage(
    /**
     * The LLM model identifier (e.g. "openai/gpt-4o", "anthropic/claude-sonnet-4-20250514").
     */
    @JsonProperty("model") String model,
    /**
     * The pipeline stage that triggered this LLM call
     * (e.g. "vlm_ocr", "structured_extraction", "embeddings").
     */
    @JsonProperty("source") String source,
    /**
     * Number of input/prompt tokens consumed.
     */
    @Nullable @JsonProperty("input_tokens") Long inputTokens,
    /**
     * Number of output/completion tokens generated.
     */
    @Nullable @JsonProperty("output_tokens") Long outputTokens,
    /**
     * Total tokens (input + output).
     */
    @Nullable @JsonProperty("total_tokens") Long totalTokens,
    /**
     * Estimated cost in USD based on the provider's published pricing.
     */
    @Nullable @JsonProperty("estimated_cost") Double estimatedCost,
    /**
     * Why the model stopped generating (e.g. "stop", "length", "content_filter").
     */
    @Nullable @JsonProperty("finish_reason") String finishReason
) {
    public static Builder builder() {
        return new Builder();
    }

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

private String model = "";
private String source = "";
        @JsonProperty("input_tokens")
private Long inputTokens = null;
        @JsonProperty("output_tokens")
private Long outputTokens = null;
        @JsonProperty("total_tokens")
private Long totalTokens = null;
        @JsonProperty("estimated_cost")
private Double estimatedCost = null;
        @JsonProperty("finish_reason")
private String finishReason = null;

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

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

        /** Sets the inputTokens field. */
        @JsonProperty("input_tokens")
        public Builder withInputTokens(final @Nullable long value) {
            this.inputTokens = value;
            return this;
        }

        /** Sets the outputTokens field. */
        @JsonProperty("output_tokens")
        public Builder withOutputTokens(final @Nullable long value) {
            this.outputTokens = value;
            return this;
        }

        /** Sets the totalTokens field. */
        @JsonProperty("total_tokens")
        public Builder withTotalTokens(final @Nullable long value) {
            this.totalTokens = value;
            return this;
        }

        /** Sets the estimatedCost field. */
        @JsonProperty("estimated_cost")
        public Builder withEstimatedCost(final @Nullable double value) {
            this.estimatedCost = value;
            return this;
        }

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

        /** Builds the LlmUsage instance. */
        public LlmUsage build() {
            return new LlmUsage(
                model,
                source,
                inputTokens,
                outputTokens,
                totalTokens,
                estimatedCost,
                finishReason
            );
        }
    }
    // CPD-ON
}
