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 { BackupsController } from './backups.controller';
import { BackupsService, SERVER_BACKUPS_QUEUE } from './backups.service';
import { ServerStateService } from '../server-state.service';

@Module({
  imports: [AuthModule, PrismaModule],
  controllers: [BackupsController],
  providers: [
    BackupsService,
    ServerStateService,
    {
      provide: SERVER_BACKUPS_QUEUE,
      useFactory: () => {
        const config = getConfig();
        return new Queue('server-backups', {
          connection: {
            url: config.REDIS_URL,
            maxRetriesPerRequest: null,
          },
        });
      },
    },
  ],
  exports: [BackupsService, SERVER_BACKUPS_QUEUE],
})
export class BackupsModule {}
