#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<std::string> 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);

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

// 文本向量化接口
class TextVectorizationInference : public TextEmbeddingInterface {
    // private:
    //     TextVectorizationInference() {}

    // // 禁止拷贝构造函数
    // TextVectorizationInference(const TextVectorizationInference&) = delete;

    // // 禁止赋值运算符
    // TextVectorizationInference& operator=(const TextVectorizationInference&)
    // =
    //     delete;

    // // 静态成员变量，保存单例实例
    // static TextVectorizationInference* instance;

    // // 静态互斥锁，用于线程同步
    // static std::mutex mutex_;

public:
    ~TextVectorizationInference() override = default;

    // 静态成员函数，用于获取单例实例
    // static TextVectorizationInference* getInstance() {
    //     std::lock_guard<std::mutex> lock(mutex_);
    //     if (instance == nullptr) {
    //         instance = new TextVectorizationInference();
    //     }
    //     return instance;
    // }

    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
