import { Global, Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bullmq';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Global()
@Module({
  imports: [
    BullModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        connection: {
          host: config.get<string>('redis.host'),
          port: config.get<number>('redis.port'),
          password: config.get<string>('redis.password'),
        },
      }),
    }),
    BullModule.registerQueue(
      { name: 'webhook-delivery' },
      { name: 'push-notification' },
      { name: 'sync-1c' },
      { name: 'email-send' },
      { name: 'crm-scheduler' },
      { name: 'booking-webhooks' },
      { name: 'booking-reminders' },
      { name: 'telegram-bot-incoming' },
      { name: 'telegram-bot-broadcast' },
      { name: 'telegram-bot-webhook' },
      { name: 'telegram-bot-delay' },
    ),
  ],
  exports: [BullModule],
})
export class QueueModule {}
