import { BaseSingleton } from '@memberjunction/global';
/**
 * Singleton manager that holds a reference to the type-graphql PubSubEngine,
 * allowing any server-side code (not just resolvers with @PubSub() injection)
 * to publish events to GraphQL subscriptions.
 */
export class PubSubManager extends BaseSingleton {
    constructor() {
        super();
        this._pubSub = null;
    }
    static get Instance() {
        return super.getInstance();
    }
    /**
     * Sets the PubSubEngine instance. Should be called once during server startup
     * after buildSchemaSync creates the PubSub instance.
     */
    SetPubSubEngine(pubSub) {
        this._pubSub = pubSub;
    }
    /**
     * Gets the current PubSubEngine instance, or null if not yet configured.
     */
    get PubSubEngine() {
        return this._pubSub;
    }
    /**
     * Publishes a payload to the specified topic via the PubSubEngine.
     * No-op if the PubSubEngine has not been configured yet.
     */
    Publish(topic, payload) {
        if (this._pubSub) {
            this._pubSub.publish(topic, payload);
        }
        else {
            console.warn(`[PubSubManager] Cannot publish to "${topic}" — PubSubEngine not set`);
        }
    }
}
//# sourceMappingURL=PubSubManager.js.map