var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var plugin_exports = {};
__export(plugin_exports, {
  PluginAdapterBullmqServer: () => PluginAdapterBullmqServer,
  default: () => plugin_default
});
module.exports = __toCommonJS(plugin_exports);
var import_api = require("@bull-board/api");
var import_bullMQAdapter = require("@bull-board/api/bullMQAdapter");
var import_koa = require("@bull-board/koa");
var import_server = require("@tego/server");
var import_bullmq = require("bullmq");
class PluginAdapterBullmqServer extends import_server.Plugin {
  async afterAdd() {
  }
  async beforeLoad() {
  }
  async load() {
    const redisOptions = {
      port: Number(process.env.REDIS_PORT || 6379),
      host: process.env.REDIS_HOST || "localhost",
      password: process.env.REDIS_PASSWORD || ""
    };
    const defaultQueue = new import_bullmq.Queue(process.env.MSG_QUEUE_NAME || "default", { connection: redisOptions });
    const serverAdapter = new import_koa.KoaAdapter();
    (0, import_api.createBullBoard)({
      queues: [new import_bullMQAdapter.BullMQAdapter(defaultQueue)],
      serverAdapter
    });
    const EXTENSION_UI_BASE_PATH = process.env.EXTENSION_UI_BASE_PATH || "/adapters/";
    serverAdapter.setBasePath(EXTENSION_UI_BASE_PATH + "mqui");
    this.app.use(serverAdapter.registerPlugin(), { before: "bodyParser" });
    this.app.on("beforeStop", async () => {
      var _a;
      await ((_a = defaultQueue == null ? void 0 : defaultQueue.close) == null ? void 0 : _a.call(defaultQueue));
    });
  }
  async install() {
  }
  async afterEnable() {
  }
  async afterDisable() {
  }
  async remove() {
  }
}
var plugin_default = PluginAdapterBullmqServer;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PluginAdapterBullmqServer
});
