import { Module, Global } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { OutboxEvent } from './outbox.entity';
import { ProcessedEvent } from './processed-event.entity';
import { OutboxService } from './outbox.service';
import { OutboxRelayService } from './outbox-relay.service';
import { IdempotencyService } from './idempotency.service';

/**
 * Outbox Module - provides transactional outbox pattern + idempotency.
 * Import this module in every NestJS service's AppModule.
 *
 * Provides:
 * - OutboxService: write events to outbox within transactions
 * - OutboxRelayService: poll and publish pending events to Kafka
 * - IdempotencyService: ensure exactly-once Kafka event processing
 */
@Global()
@Module({
  imports: [TypeOrmModule.forFeature([OutboxEvent, ProcessedEvent])],
  providers: [OutboxService, OutboxRelayService, IdempotencyService],
  exports: [OutboxService, IdempotencyService],
})
export class OutboxModule {}
