import {
  __decorateClass
} from "./chunk-2E224ZSN.js";

// runtime/subsystems/integration/integration-cursor-store.memory-backend.ts
import { Injectable } from "@nestjs/common";
var MemoryCursorStore = class {
  /**
   * Subscription-id → last persisted cursor. Public so tests can inspect
   * or pre-seed state; production callers MUST go through `get`/`put`.
   */
  cursors = /* @__PURE__ */ new Map();
  /**
   * Seedable subscription metadata for `listAll` — the memory backend
   * stores only `subscriptionId → cursor` in its write path, so the
   * snapshot shape (`connectionId`, `adapter`, `domain`, `externalRef`,
   * timestamps) has no natural source without test seeding. Tests populate
   * this map; unseeded entries get empty-string metadata and `new Date(0)`
   * timestamps so the shape stays stable. Production paths go through the
   * Drizzle backend.
   */
  subscriptions = /* @__PURE__ */ new Map();
  async get(subscriptionId, _tenantId) {
    const value = this.cursors.get(subscriptionId);
    return value === void 0 ? null : value;
  }
  async put(subscriptionId, cursor, _tenantId) {
    this.cursors.set(subscriptionId, cursor);
  }
  async listAll(_tenantId) {
    const snapshots = [];
    for (const [subscriptionId, cursor] of this.cursors.entries()) {
      const meta = this.subscriptions.get(subscriptionId);
      snapshots.push({
        subscriptionId,
        connectionId: meta?.connectionId ?? "",
        adapter: meta?.adapter ?? "",
        domain: meta?.domain ?? "",
        externalRef: meta?.externalRef ?? null,
        cursor: cursor ?? null,
        lastIntegrationAt: meta?.lastIntegrationAt ?? null,
        updatedAt: meta?.updatedAt ?? /* @__PURE__ */ new Date(0),
        tenantId: null
      });
    }
    return snapshots.sort(
      (a, b) => b.updatedAt.getTime() - a.updatedAt.getTime()
    );
  }
  /** Reset state. Tests call this in `beforeEach`. */
  clear() {
    this.cursors.clear();
    this.subscriptions.clear();
  }
};
MemoryCursorStore = __decorateClass([
  Injectable()
], MemoryCursorStore);

export {
  MemoryCursorStore
};
//# sourceMappingURL=chunk-AHV4GDYM.js.map