// Message Bus Integration - RabbitMQ/Kafka

import { logger } from '@/infrastructure/monitoring/logger';
import { wrapGatewayMqMessageHandler } from '@/core/gateway/rails/gateway-mq-wrap';

export class MessageBusService {
  /**
   * Publish message to queue
   */
  async publishMessage(queue: string, message: any): Promise<void> {
    // In production, this would publish to RabbitMQ or Kafka
    logger.info(`Publishing message to queue: ${queue}`, { message });
  }

  /**
   * Subscribe to queue
   */
  async subscribeToQueue(queue: string, handler: (message: any) => Promise<void>): Promise<void> {
    // In production, this would subscribe to RabbitMQ or Kafka
    logger.info(`Subscribing to queue: ${queue}`);
  }

  /**
   * Build a handler for amqplib/kafkajs consumers: SolaceNet enforcement on `dbis.gateway.*`
   * queues (prefix overridable via `SOLACENET_GATEWAY_MQ_QUEUE_PREFIX`) when
   * `SOLACENET_GATEWAY_RAILS_ENFORCE` is on.
   */
  buildGatewayAwareHandler(
    queue: string,
    handler: (message: any) => Promise<void>,
  ): (message: unknown) => Promise<void> {
    return wrapGatewayMqMessageHandler(queue, handler);
  }
}

export const messageBusService = new MessageBusService();

