package com.easyagents.rag.ingestion;

import com.easyagents.rag.core.RagChunk;
import com.easyagents.rag.ingestion.analysis.DocumentStructureAnalyzer;
import com.easyagents.rag.ingestion.chunk.RagSplitStrategyRegistry;
import com.easyagents.rag.ingestion.model.AnalysisResult;
import com.easyagents.rag.ingestion.model.StrategyConfig;
import com.easyagents.rag.ingestion.recommend.SplitStrategyRecommender;

import java.util.List;

public class DefaultRagIngestionService implements RagIngestionService {

    private final DocumentStructureAnalyzer documentStructureAnalyzer;
    private final SplitStrategyRecommender splitStrategyRecommender;
    private final RagSplitStrategyRegistry ragSplitStrategyRegistry;

    public DefaultRagIngestionService(DocumentStructureAnalyzer documentStructureAnalyzer,
                                      SplitStrategyRecommender splitStrategyRecommender,
                                      RagSplitStrategyRegistry ragSplitStrategyRegistry) {
        this.documentStructureAnalyzer = documentStructureAnalyzer;
        this.splitStrategyRecommender = splitStrategyRecommender;
        this.ragSplitStrategyRegistry = ragSplitStrategyRegistry;
    }

    @Override
    public AnalysisResult analyze(String rawContent, String sourceFormat) {
        AnalysisResult result = documentStructureAnalyzer.analyze(rawContent, sourceFormat);
        return splitStrategyRecommender.recommend(result);
    }

    @Override
    public List<RagChunk> split(AnalysisResult analysis, StrategyConfig config) {
        return ragSplitStrategyRegistry.split(analysis, config);
    }

    @Override
    public String toStrategyLabel(String strategyCode) {
        return splitStrategyRecommender.toStrategyLabel(strategyCode);
    }
}
