// Force strict mode and setup for ESM
"use strict";
import {
  init_esbuild_shims
} from "./chunk-5O2XNYP6.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/cli/src/commands/channel/channel-registry.ts
init_esbuild_shims();
var registry = /* @__PURE__ */ new Map();
var builtinsPromise = null;
function ensureBuiltins() {
  if (!builtinsPromise) {
    builtinsPromise = (async () => {
      const labelled = [
        { name: "telegram", promise: import("./dist-ZHXOBXDN.js") },
        { name: "weixin", promise: import("./dist-OAOC5OV4.js") },
        { name: "dingtalk", promise: import("./dist-SL2LUMML.js") },
        { name: "wecom", promise: import("./dist-PVEAFLHY.js") },
        { name: "feishu", promise: import("./dist-2PERFI23.js") },
        { name: "qqbot", promise: import("./dist-WGMNT3JQ.js") },
        { name: "github", promise: import("./dist-26BIMQT6.js") },
        { name: "gitlab", promise: import("./dist-ULIG4M5H.js") }
      ];
      const results = await Promise.allSettled(labelled.map((l) => l.promise));
      for (let i = 0; i < results.length; i++) {
        const result = results[i];
        if (result.status === "fulfilled") {
          registry.set(result.value.plugin.channelType, result.value.plugin);
        } else {
          process.stderr.write(
            `[channel-registry] Failed to load "${labelled[i].name}" channel: ${result.reason}
`
          );
        }
      }
    })();
  }
  return builtinsPromise;
}
__name(ensureBuiltins, "ensureBuiltins");
function registerPlugin(plugin) {
  if (registry.has(plugin.channelType)) {
    throw new Error(
      `Channel type "${plugin.channelType}" is already registered.`
    );
  }
  registry.set(plugin.channelType, plugin);
}
__name(registerPlugin, "registerPlugin");
async function getPlugin(channelType) {
  await ensureBuiltins();
  return registry.get(channelType);
}
__name(getPlugin, "getPlugin");
async function supportedTypes() {
  await ensureBuiltins();
  return [...registry.keys()];
}
__name(supportedTypes, "supportedTypes");
async function supportedChannelCatalog() {
  await ensureBuiltins();
  return [...registry.values()].map(
    ({ channelType, displayName, management }) => ({
      type: channelType,
      displayName,
      manageable: management !== void 0,
      fields: management?.fields ?? []
    })
  );
}
__name(supportedChannelCatalog, "supportedChannelCatalog");

export {
  registerPlugin,
  getPlugin,
  supportedTypes,
  supportedChannelCatalog
};
