import {
  OBSERVABILITY,
  OBSERVABILITY_MODULE_OPTIONS
} from "./chunk-Y7RRSEOC.js";
import {
  __decorateClass,
  __decorateParam
} from "./chunk-2E224ZSN.js";

// runtime/subsystems/observability/reporters/bridge-metrics.reporter.ts
import {
  Inject,
  Injectable,
  Logger
} from "@nestjs/common";
var BridgeMetricsReporter = class {
  constructor(observability, options) {
    this.observability = observability;
    this.config = options.reporters?.bridgeMetrics;
  }
  observability;
  logger = new Logger(BridgeMetricsReporter.name);
  handle = null;
  config;
  onModuleInit() {
    if (!this.config || !this.config.enabled) {
      this.logger.log("BridgeMetricsReporter disabled");
      return;
    }
    if (this.config.intervalMs <= 0 || this.config.windowHours <= 0) {
      this.logger.warn(
        `invalid config; not starting: intervalMs=${this.config.intervalMs} windowHours=${this.config.windowHours}`
      );
      return;
    }
    void this.runOnce();
    this.handle = setInterval(() => {
      void this.runOnce();
    }, this.config.intervalMs);
    if (typeof this.handle.unref === "function") this.handle.unref();
  }
  onModuleDestroy() {
    if (this.handle !== null) {
      clearInterval(this.handle);
      this.handle = null;
    }
  }
  /**
   * Single sample. Public so tests and future ops tooling can trigger a
   * sample on demand without waiting for the interval. Errors are caught
   * and logged here — never rethrown — so a transient sibling failure
   * does not kill subsequent ticks.
   */
  async runOnce() {
    if (!this.config || !this.config.enabled) return;
    try {
      const h = await this.observability.getBridgeDeliveryHistogram(
        this.config.windowHours,
        this.config.tenantId
      );
      this.logger.log(
        `bridge-delivery window=${this.config.windowHours}h tenant=${this.config.tenantId ?? "default"} pending=${h.pending} delivered=${h.delivered} skipped=${h.skipped} failed=${h.failed}`
      );
    } catch (err) {
      this.logger.error(
        "BridgeMetricsReporter runOnce failed",
        err instanceof Error ? err.stack : String(err)
      );
    }
  }
};
BridgeMetricsReporter = __decorateClass([
  Injectable(),
  __decorateParam(0, Inject(OBSERVABILITY)),
  __decorateParam(1, Inject(OBSERVABILITY_MODULE_OPTIONS))
], BridgeMetricsReporter);

export {
  BridgeMetricsReporter
};
//# sourceMappingURL=chunk-AQFQ4BYM.js.map