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, {
  PluginDingdingServer: () => PluginDingdingServer,
  default: () => plugin_default
});
module.exports = __toCommonJS(plugin_exports);
var import_server = require("@tego/server");
var import_constants = require("../constants");
var import_dingding = require("./actions/dingding");
var import_dingtalk_auth = require("./dingtalk-auth");
class PluginDingdingServer extends import_server.Plugin {
  async afterAdd() {
  }
  async beforeLoad() {
  }
  async load() {
    this.app.authManager.registerTypes(import_constants.authType, {
      auth: import_dingtalk_auth.DingtalkAuth
    });
    this.app.resourcer.define({
      name: "dingtalk",
      actions: {
        getAuthUrl: import_dingding.getAuthUrl,
        redirect: import_dingding.redirect
      }
    });
    this.app.acl.allow("dingtalk", "*", "public");
    import_server.Gateway.getInstance().addAppSelectorMiddleware(async (ctx, next) => {
      const { req } = ctx;
      const url = new URL(req.url, `http://${req.headers.host}`);
      const params = url.searchParams;
      const state = params.get("state");
      if (!state) {
        return next();
      }
      const search = new URLSearchParams(state);
      const appName = search.get("app");
      if (appName) {
        ctx.resolvedAppName = appName;
      }
      await next();
    });
  }
  async install() {
  }
  async afterEnable() {
  }
  async afterDisable() {
  }
  async remove() {
  }
}
var plugin_default = PluginDingdingServer;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PluginDingdingServer
});
