import { Module } from '@nestjs/common';
import { Queue } from 'bullmq';

import { getConfig } from '@hexahost/config';

import { AuthModule } from '../../auth/auth.module';
import { PrismaModule } from '../../prisma/prisma.module';
import { ServerStateService } from '../server-state.service';

import { AddonsController } from './addons.controller';
import { AddonsService, SERVER_ADDONS_QUEUE } from './addons.service';

@Module({
  imports: [AuthModule, PrismaModule],
  controllers: [AddonsController],
  providers: [
    AddonsService,
    ServerStateService,
    {
      provide: SERVER_ADDONS_QUEUE,
      useFactory: () => {
        const config = getConfig();
        return new Queue('server-addons', {
          connection: {
            url: config.REDIS_URL,
            maxRetriesPerRequest: null,
          },
        });
      },
    },
  ],
  exports: [AddonsService],
})
export class AddonsModule {}
