package at.procon.ted.config;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;

/**
 * Legacy vectorization configuration used only by the old runtime path.
 * <p>
 * This extracts the former ted.vectorization.* subtree away from TedProcessorProperties
 * so that legacy vectorization beans no longer depend on the shared monolithic config.
 */
@Configuration
@ConfigurationProperties(prefix = "legacy.ted.vectorization")
@Data
@Validated
public class LegacyVectorizationProperties {

    /**
     * Enable/disable legacy async vectorization.
     */
    private boolean enabled = true;

    /**
     * Use external HTTP API instead of Python subprocess.
     */
    private boolean useHttpApi = false;

    /**
     * Embedding service HTTP API URL.
     */
    private String apiUrl = "http://localhost:8001";

    /**
     * Sentence transformer model name.
     */
    private String modelName = "intfloat/multilingual-e5-large";

    /**
     * Vector dimensions (must match model output).
     */
    @Positive
    private int dimensions = 1024;

    /**
     * Batch size for vectorization processing.
     */
    @Min(1)
    private int batchSize = 16;

    /**
     * Thread pool size for async vectorization.
     */
    @Min(1)
    private int threadPoolSize = 4;

    /**
     * Maximum text length for vectorization (characters).
     */
    @Positive
    private int maxTextLength = 8192;

    /**
     * HTTP connection timeout in milliseconds.
     */
    @Positive
    private int connectTimeout = 10000;

    /**
     * HTTP socket/read timeout in milliseconds.
     */
    @Positive
    private int socketTimeout = 60000;

    /**
     * Maximum retries on connection failure.
     */
    @Min(0)
    private int maxRetries = 5;

    /**
     * Enable the former Phase 2 generic pipeline in the legacy runtime.
     * In the split runtime design this should normally stay false in NEW mode
     * because legacy beans are not instantiated there.
     */
    private boolean genericPipelineEnabled = true;

    /**
     * Keep writing completed TED embeddings back to the legacy ted.procurement_document
     * vector columns so the existing semantic search stays operational during migration.
     */
    private boolean dualWriteLegacyTedVectors = true;

    /**
     * Scheduler interval for generic embedding polling (milliseconds).
     */
    @Positive
    private long genericSchedulerPeriodMs = 6000;

    /**
     * Builder key for the primary TED semantic representation created during transitional dual-write.
     */
    @NotBlank
    private String primaryRepresentationBuilderKey = "ted-phase2-primary-representation";

    /**
     * Provider key used when registering the configured embedding model in DOC.doc_embedding_model.
     */
    @NotBlank
    private String embeddingProvider = "http-embedding-service";
}