// @File: system_scenario_class.h
// @Author: hanxy
// @Date: 2024/11/14
// @Software: VScode
// @Description: The header file for system scenario

#ifndef SYSTEM_SCENARIO_H
#define SYSTEM_SCENARIO_H

#include <jsoncpp/json/json.h>

#include <filesystem>
#include <map>
#include <string>

#include "dialoguemessage.h"

// 定义基类B
class BaseFunction {
public:
    // 构造函数
    BaseFunction();
    ~BaseFunction();
    void loadPrompt(const std::string &intentPromptFile);
    static Json::Value loadJsonFile(const std::string &jsonFile);

    std::string readTxtFile(const std::string &file_path);

    std::string getIntentPrompt();  // 获取私有数据成员的函数
    void getpromptReplaceText(std::string &newReplaceText);

private:
    std::string intentPrompt_;
    std::string promptReplaceText_;
};

// 会话记忆
class DialogueMemory : public BaseFunction {
public:
    bool isJsonLoaded = false;

public:
    DialogueMemory();
    ~DialogueMemory();

    void loadDialogueData(std::vector<std::filesystem::path> foundDialogueFile, const std::string &targetString,
                          std::string &dialogueId);

    void updateHistorySessionToFile(const bool &isFirstRound, const DialogueData::Dialogue &currentDialogue);

    // // 根据当前轮次意图检索历史对话
    DialogueData::Intent retrieveHistoryDialogue(DialogueData::Dialogue &allHistoryDialogue,
                                                 DialogueData::Intent &curTurnIntent);

    Json::Value getDialogueHistoryData();
    std::vector<DialogueData::DialogueTurn> getRelevantHistoryData();

private:
    Json::Value historyDialogueMerge;
    std::vector<DialogueData::DialogueTurn> relevantHistoryData;
};

void findFilesWithString(const std::filesystem::path &fileDirectory, const std::string &targetString,
                         std::string &dialogueId, DialogueMemory &dialogueMemory);

#endif  // SYSTEM_SCENARIO_H
