"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConversationHistoryController = void 0;
const ConversationHistoryModel_1 = require("../models/ConversationHistoryModel");
const tiktoken_instance_1 = require("../utils/tiktoken-instance");
class ConversationHistoryController {
    constructor() {
        this.conversationModel = new ConversationHistoryModel_1.ConversationHistoryModel();
    }
    appendAIMessage(content) {
        return __awaiter(this, void 0, void 0, function* () {
            const tokenLength = yield (0, tiktoken_instance_1.getTokenLengthByInput)(content);
            this.conversationModel.appendAIMessage({ content, tokenLength });
        });
    }
    appendUserMessage(content) {
        return __awaiter(this, void 0, void 0, function* () {
            const tokenLength = yield (0, tiktoken_instance_1.getTokenLengthByInput)(content);
            this.conversationModel.appendUserMessage({ content, tokenLength });
        });
    }
    getConversationHistory() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.conversationModel.getConversationHistory();
        });
    }
    resetConversationHistory() {
        return __awaiter(this, void 0, void 0, function* () {
            this.conversationModel.resetConversationHistory();
        });
    }
    setConversationHistory(messages) {
        return __awaiter(this, void 0, void 0, function* () {
            // lets take advantage of existing interfaces, and use the append methods
            for (const message of messages) {
                if (message.key === "user") {
                    yield this.appendUserMessage(message.content);
                }
                else {
                    yield this.appendAIMessage(message.content);
                }
            }
        });
    }
}
exports.ConversationHistoryController = ConversationHistoryController;
