var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/modules/ScanOrderLogger/index.ts
var ScanOrderLogger_exports = {};
__export(ScanOrderLogger_exports, {
  ScanOrderLoggerModule: () => ScanOrderLoggerModule
});
module.exports = __toCommonJS(ScanOrderLogger_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_BaseModule = require("../BaseModule");
var import_feishu = require("./providers/feishu");
var import_grafana = require("./providers/grafana");
__reExport(ScanOrderLogger_exports, require("./types"), module.exports);
var defaultProviderConfig = {
  feishu: {
    webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/REPLACE_ME"
  },
  grafana: {
    endpoint: "https://grafana.example.com/collect"
  }
};
var providerMap = {
  feishu: import_feishu.feishuLoggerProvider,
  grafana: import_grafana.grafanaLoggerProvider
};
var ScanOrderLoggerModule = class extends import_BaseModule.BaseModule {
  constructor() {
    super(...arguments);
    this.defaultName = "scanOrderLogger";
    this.defaultVersion = "1.0.0";
  }
  async initialize(core, options = {}) {
    var _a, _b, _c;
    this.core = core;
    this.store = options.store;
    const provider = ((_a = options.otherParams) == null ? void 0 : _a.provider) || "feishu";
    const providerConfig = ((_b = options.otherParams) == null ? void 0 : _b.providerConfig) || {};
    const context = ((_c = options.otherParams) == null ? void 0 : _c.context) || {};
    this.store.provider = provider;
    this.store.providerConfig = {
      ...defaultProviderConfig,
      ...providerConfig,
      feishu: {
        ...defaultProviderConfig.feishu,
        ...providerConfig.feishu || {}
      },
      grafana: {
        ...defaultProviderConfig.grafana,
        ...providerConfig.grafana || {}
      }
    };
    this.store.context = context;
  }
  setContext(context) {
    this.store.context = {
      ...this.store.context,
      ...context
    };
  }
  setProvider(provider) {
    this.store.provider = provider;
  }
  setProviderConfig(providerConfig) {
    this.store.providerConfig = {
      ...this.store.providerConfig,
      ...providerConfig,
      feishu: {
        ...this.store.providerConfig.feishu || {},
        ...providerConfig.feishu || {}
      },
      grafana: {
        ...this.store.providerConfig.grafana || {},
        ...providerConfig.grafana || {}
      }
    };
  }
  buildRecord(params) {
    return {
      level: params.level || "info",
      title: params.title,
      timestamp: params.timestamp || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
      payload: params.payload || {},
      extra: params.extra || {},
      context: this.store.context || {}
    };
  }
  async addLog(params) {
    if (!params.title) {
      console.warn("[ScanOrderLogger] 缺少日志标题，已跳过");
      return;
    }
    const provider = providerMap[this.store.provider] || import_feishu.feishuLoggerProvider;
    const record = this.buildRecord(params);
    try {
      await provider.send({
        record,
        providerConfig: this.store.providerConfig
      });
    } catch (error) {
      console.warn("[ScanOrderLogger] 日志上报失败", error);
    }
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ScanOrderLoggerModule,
  ...require("./types")
});
