"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutboxNotifier = void 0;
const common_1 = require("@nestjs/common");
const events_1 = require("events");
/**
 * In-memory notifier for signaling new outbox events
 * Provides immediate wakeup to the processor without database polling
 * NOT the source of truth; database outbox is the authoritative queue
 */
let OutboxNotifier = class OutboxNotifier {
    constructor() {
        this.emitter = new events_1.EventEmitter();
        this.EVENT_WRITTEN = 'outbox:event:written';
    }
    /**
     * Subscribe to outbox event notifications
     */
    subscribe(listener) {
        this.emitter.on(this.EVENT_WRITTEN, listener);
    }
    /**
     * Unsubscribe from outbox event notifications
     */
    unsubscribe(listener) {
        this.emitter.removeListener(this.EVENT_WRITTEN, listener);
    }
    /**
     * Emit notification that a new event was written to outbox
     */
    notifyEventWritten() {
        this.emitter.emit(this.EVENT_WRITTEN);
    }
    /**
     * Get current number of subscribers
     */
    getSubscriberCount() {
        return this.emitter.listenerCount(this.EVENT_WRITTEN);
    }
    /**
     * Remove all listeners
     */
    removeAllListeners() {
        this.emitter.removeAllListeners(this.EVENT_WRITTEN);
    }
};
exports.OutboxNotifier = OutboxNotifier;
exports.OutboxNotifier = OutboxNotifier = __decorate([
    (0, common_1.Injectable)()
], OutboxNotifier);
//# sourceMappingURL=outbox.notifier.js.map