#ifndef SERVICES_ASSISTANT_FILE_INFERENCE_H
#define SERVICES_ASSISTANT_FILE_INFERENCE_H

#include <gio/gio.h>
#include <kylin-ai/ai-engine/embeddingengine.h>

#include <future>

#include "assistant/rag/ragserverproxy.h"
#include "fileinferenceinterface.h"

namespace assistant::session {
struct DialogueSession;
}

class FileInference : public FileInferenceInterface {
public:
    ~FileInference() override = default;

    std::future<DialogueData::FileSearchIdentifier> ragSearchText(const std::string& knowledgeBaseName,
                                                                  const std::string& text, bool useDefault) override;

    DialogueData::CallSuccessIdentifier fileContent(const std::string& knowledgeBaseName,
                                                    const std::string& filePath) override;

    std::future<DialogueData::KnowledgeBaseResult> createFileKnowledgeBase() override;

    void deleteFileKnowledgeBase(const std::string& knowledgeBaseName) override;

    DialogueData::FileSearchIdentifier updateFileKnowledgeBase(const std::string& knowledgeBaseName,
                                                               const std::string& docFilePath) override;

private:
    RagServerProxy::SimilaritySearchResults searchFileContent(const std::string& question,
                                                              const std::string& knowledgeBaseName,
                                                              RagErrorInfo& error);

private:
    RagServerProxy& ragServerProxy_{RagServerProxy::instance()};
};

// 文本向量化接口
class TextVectorizationInference : public TextEmbeddingInterface {
public:
    ~TextVectorizationInference() override = default;

    void initEmbeddingEngine(
        const std::shared_ptr<ai_engine::core_ai::embedding::AbstractEmbeddingEngine>& textEmbeddingEngine) {
        textEmbeddingEngine_ = textEmbeddingEngine;
    }

    // 实现文本向量化调用
    DialogueCallback::TextEmbeddingResult textVectorization(const std::string& textStr);

protected:
    std::shared_ptr<ai_engine::core_ai::embedding::AbstractEmbeddingEngine> textEmbeddingEngine_{nullptr};
};

#endif  // SERVICES_ASSISTANT_FILE_INFERENCE_H
