"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Memory = void 0;
const ChatHistory_1 = require("./ChatHistory");
class Memory {
    constructor() {
        this.memory = new Map();
    }
    addChatHistory(message, type, sessionID) {
        if (sessionID != null) {
            let chatHistory = this.memory.get(sessionID);
            if (chatHistory) {
                let message_with_session = `Session ID: ${sessionID}\n` + message;
                chatHistory.addMessage(message_with_session, type);
            }
            else {
                throw new Error(`Chat history not found for session ID: ${sessionID}`);
            }
        }
        else {
            let newChatHistory = new ChatHistory_1.ChatHistory();
            sessionID = newChatHistory.getSessionId();
            let message_with_session = `Session ID: ${sessionID}\n` + message;
            newChatHistory.addMessage(message_with_session, type);
            this.memory.set(sessionID, newChatHistory);
        }
        return sessionID;
    }
    getChatHistory(userId) {
        let chatHistory = this.memory.get(userId);
        if (chatHistory) {
            return chatHistory;
        }
        else {
            throw new Error("Memory not found");
        }
    }
}
exports.Memory = Memory;
