"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.reminderOwnersRegistry = exports.toolsetMetaRegistry = exports.toolsetsRegistry = exports.toolsRegistry = void 0;
exports.registerTool = registerTool;
exports.unregisterTool = unregisterTool;
exports.getTool = getTool;
exports.listTools = listTools;
exports.registerToolset = registerToolset;
exports.unregisterToolset = unregisterToolset;
exports.setToolsetMeta = setToolsetMeta;
exports.getToolsetMeta = getToolsetMeta;
exports.getToolsetPromptI18n = getToolsetPromptI18n;
exports.getToolset = getToolset;
exports.listToolsets = listToolsets;
exports.registerReminderOwner = registerReminderOwner;
exports.unregisterReminderOwner = unregisterReminderOwner;
exports.getReminderOwner = getReminderOwner;
exports.listReminderOwners = listReminderOwners;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// Global public registry of tools, shared across the application
exports.toolsRegistry = new Map();
// Global public registry of toolsets, shared across the application
exports.toolsetsRegistry = new Map();
exports.toolsetMetaRegistry = new Map();
// Global public registry of ReminderOwner instances, shared across the application
exports.reminderOwnersRegistry = new Map();
// Register a tool object by name
function registerTool(tool) {
    exports.toolsRegistry.set(tool.name, tool);
}
// Unregister a tool by name
function unregisterTool(name) {
    exports.toolsRegistry.delete(name);
}
// Retrieve a tool by name
function getTool(name) {
    return exports.toolsRegistry.get(name);
}
// List all registered tools
function listTools() {
    return Array.from(exports.toolsRegistry.values());
}
// Register a toolset by name with a list of tool objects
function registerToolset(name, tools) {
    exports.toolsetsRegistry.set(name, tools);
}
// Unregister a toolset by name
function unregisterToolset(name) {
    exports.toolsetsRegistry.delete(name);
    exports.toolsetMetaRegistry.delete(name);
}
function setToolsetMeta(name, meta) {
    exports.toolsetMetaRegistry.set(name, meta);
}
function getToolsetMeta(name) {
    return exports.toolsetMetaRegistry.get(name);
}
function getToolsetPromptI18n(name) {
    const meta = getToolsetMeta(name);
    if (!meta)
        return undefined;
    if (meta.promptI18n)
        return meta.promptI18n;
    if (!meta.promptFilesI18n)
        return undefined;
    const enPath = meta.promptFilesI18n.en;
    const zhPath = meta.promptFilesI18n.zh;
    if (!enPath || !zhPath)
        return undefined;
    const tryRead = (relPath) => {
        const abs = path_1.default.resolve(__dirname, relPath);
        try {
            return fs_1.default.readFileSync(abs, 'utf8');
        }
        catch {
            return '';
        }
    };
    const en = tryRead(enPath);
    const zh = tryRead(zhPath);
    if (en.trim() === '' || zh.trim() === '')
        return undefined;
    return { en, zh };
}
// Retrieve a toolset by name (returns array of tool objects)
function getToolset(name) {
    return exports.toolsetsRegistry.get(name);
}
// List all registered toolsets
function listToolsets() {
    return Object.fromEntries(exports.toolsetsRegistry.entries());
}
// Register a ReminderOwner by unique name
function registerReminderOwner(owner, name) {
    const ownerName = name || owner.name;
    if (!ownerName) {
        throw new Error('ReminderOwner must have a name property or name must be provided explicitly');
    }
    exports.reminderOwnersRegistry.set(ownerName, owner);
}
// Unregister a ReminderOwner by name
function unregisterReminderOwner(name) {
    exports.reminderOwnersRegistry.delete(name);
}
// Retrieve a ReminderOwner by name
function getReminderOwner(name) {
    return exports.reminderOwnersRegistry.get(name);
}
// List all registered ReminderOwners
function listReminderOwners() {
    return new Map(exports.reminderOwnersRegistry);
}
