package com.easyagents.spring.boot.rag.ingestion;

import com.easyagents.rag.ingestion.DefaultRagIngestionService;
import com.easyagents.rag.ingestion.RagIngestionService;
import com.easyagents.rag.ingestion.analysis.DocumentStructureAnalyzer;
import com.easyagents.rag.ingestion.chunk.RagSplitStrategyRegistry;
import com.easyagents.rag.ingestion.recommend.SplitStrategyRecommender;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ConditionalOnClass(RagIngestionService.class)
@Configuration(proxyBeanMethods = false)
public class RagIngestionAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public DocumentStructureAnalyzer documentStructureAnalyzer() {
        return new DocumentStructureAnalyzer();
    }

    @Bean
    @ConditionalOnMissingBean
    public SplitStrategyRecommender splitStrategyRecommender() {
        return new SplitStrategyRecommender();
    }

    @Bean
    @ConditionalOnMissingBean
    public RagSplitStrategyRegistry ragSplitStrategyRegistry() {
        return new RagSplitStrategyRegistry();
    }

    @Bean
    @ConditionalOnMissingBean
    public RagIngestionService ragIngestionService(DocumentStructureAnalyzer documentStructureAnalyzer,
                                                   SplitStrategyRecommender splitStrategyRecommender,
                                                   RagSplitStrategyRegistry ragSplitStrategyRegistry) {
        return new DefaultRagIngestionService(documentStructureAnalyzer, splitStrategyRecommender, ragSplitStrategyRegistry);
    }
}
