import { Module, Global } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { PrismaModule } from './persistence/prisma/prisma.module';
import { RedisService } from './redis/redis.service';
import { KafkaModule } from './kafka/kafka.module';

@Global()
@Module({
  imports: [PrismaModule, KafkaModule],
  providers: [
    {
      provide: 'REDIS_OPTIONS',
      useFactory: (configService: ConfigService) => ({
        host: configService.get<string>('REDIS_HOST', 'localhost'),
        port: configService.get<number>('REDIS_PORT', 6379),
        password: configService.get<string>('REDIS_PASSWORD'),
        db: configService.get<number>('REDIS_DB', 13),
      }),
      inject: [ConfigService],
    },
    RedisService,
  ],
  exports: [PrismaModule, RedisService, KafkaModule],
})
export class InfrastructureModule {}
