import { createLogger } from "../utils/logger/index.js";
import { init_logger } from "../utils/logger.js";
//#region src/extensions/extension-registry-impl.ts
init_logger();
const log = createLogger("ExtensionRegistry");
var ExtensionRegistryImpl = class {
	extensions = /* @__PURE__ */ new Map();
	hooks = /* @__PURE__ */ new Map();
	httpRoutes = /* @__PURE__ */ new Map();
	commands = /* @__PURE__ */ new Map();
	services = /* @__PURE__ */ new Map();
	gatewayMethods = /* @__PURE__ */ new Map();
	tools = /* @__PURE__ */ new Map();
	channelPlugins = [];
	cliRegistrations = [];
	reloadRegistrations = [];
	tuiRegistrations = [];
	addExtension(record) {
		this.extensions.set(record.id, record);
	}
	getExtension(id) {
		return this.extensions.get(id);
	}
	getEnabledExtensions() {
		return Array.from(this.extensions.values()).filter((p) => p.enabled);
	}
	addHook(event, handler, _extensionId, _priority = 0) {
		if (!this.hooks.has(event)) this.hooks.set(event, []);
		this.hooks.get(event).push(handler);
	}
	getHooks(event) {
		return this.hooks.get(event) || [];
	}
	addChannelPlugin(plugin) {
		this.channelPlugins = this.channelPlugins.filter((p) => p.id !== plugin.id);
		this.channelPlugins.push(plugin);
	}
	addHttpRoute(path, handler) {
		if (this.httpRoutes.has(path)) log.warn({ path }, `HTTP route already registered, overwriting`);
		this.httpRoutes.set(path, handler);
	}
	getHttpRoute(path) {
		return this.httpRoutes.get(path);
	}
	addCommand(command) {
		if (this.commands.has(command.name)) log.warn({ command: command.name }, `Command already registered, overwriting`);
		this.commands.set(command.name, command);
	}
	getCommand(name) {
		return this.commands.get(name);
	}
	addService(service) {
		if (this.services.has(service.id)) log.warn({ service: service.id }, `Service already registered, overwriting`);
		this.services.set(service.id, service);
	}
	getService(id) {
		return this.services.get(id);
	}
	addGatewayMethod(method, handler) {
		if (this.gatewayMethods.has(method)) log.warn({ method }, `Gateway method already registered, overwriting`);
		this.gatewayMethods.set(method, handler);
	}
	getGatewayMethod(method) {
		return this.gatewayMethods.get(method);
	}
	addTool(tool) {
		if (this.tools.has(tool.name)) log.warn({ tool: tool.name }, `Tool already registered, overwriting`);
		this.tools.set(tool.name, tool);
	}
	removeTool(name) {
		this.tools.delete(name);
	}
	getTools() {
		return this.tools;
	}
	getTool(name) {
		return this.tools.get(name);
	}
	getAllTools() {
		return Array.from(this.tools.values());
	}
	addCliRegistration(reg) {
		this.cliRegistrations.push(reg);
	}
	getCliRegistrations() {
		return this.cliRegistrations;
	}
	addTuiRegistration(extensionId, register) {
		this.tuiRegistrations.push({
			extensionId,
			register
		});
	}
	getTuiRegistrations() {
		return this.tuiRegistrations;
	}
	addReloadRegistration(reg) {
		this.reloadRegistrations = this.reloadRegistrations.filter((r) => r.extensionId !== reg.extensionId);
		this.reloadRegistrations.push(reg);
	}
	removeReloadRegistration(extensionId) {
		this.reloadRegistrations = this.reloadRegistrations.filter((r) => r.extensionId !== extensionId);
	}
	getReloadRegistrations() {
		return this.reloadRegistrations;
	}
	getMatchingReloadRegistrations(changedPaths) {
		return this.reloadRegistrations.filter((reg) => {
			if (reg.configPrefixes.length === 0) return true;
			return reg.configPrefixes.some((prefix) => changedPaths.some((path) => path === prefix || path.startsWith(`${prefix}.`)));
		});
	}
};
//#endregion
export { ExtensionRegistryImpl };

//# sourceMappingURL=extension-registry-impl.js.map