package com.emoon.knowledge.chain.loader;

import com.emoon.knowledge.chain.constant.FileType;
import com.emoon.knowledge.chain.split.CharacterTextSplitter;
import com.emoon.knowledge.chain.split.CodeTextSplitter;
import com.emoon.knowledge.chain.split.MarkdownTextSplitter;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

@AllArgsConstructor
@Component
public class ResourceLoaderFactory {
    @Resource
    private final CharacterTextSplitter characterTextSplitter;
    @Resource
    private final CodeTextSplitter codeTextSplitter;
    @Resource
    private final MarkdownTextSplitter markdownTextSplitter;


    public ResourceLoader getLoaderByFileType(String fileType){
        if (FileType.isTextFile(fileType)){
            return new TextFileLoader(characterTextSplitter);
        } else if (FileType.isWord(fileType)) {
            return new WordLoader(characterTextSplitter);
        } else if (FileType.isPdf(fileType)) {
            return new PdfFileLoader(characterTextSplitter);
        } else if (FileType.isMdFile(fileType)) {
            return new MarkDownFileLoader(markdownTextSplitter);
        }else if (FileType.isCodeFile(fileType)) {
            return new CodeFileLoader(codeTextSplitter);
        } else if (FileType.isExcel(fileType)) {
            return new ExcelFileLoader(characterTextSplitter);
        } else {
            return new TextFileLoader(characterTextSplitter);
        }
    }
}
