import { forwardRef, Global, Module } from '@nestjs/common';
import { GameService } from './game.service';
import { CqrsModule } from '@nestjs/cqrs';
import { QuizAnsweredEventHandler } from './event-handlers/quiz-answered-event.handler';
import { CardSelectionPendingEventHandler } from './event-handlers/card-selection-pending-event.handler';
import { PlayerCardSelectedEventHandler } from './event-handlers/player-card-selected-event.handler';
import { MongooseModule } from '@nestjs/mongoose';
import { GameQueue, GameQueueSchema } from '../schemas/game-queue.schema';
import { CreateNewQueueItemCommandHandler } from './comand-handlers/create-new-queue-item-command.handler';
import { GamePrepareGameEventHandler } from './event-handlers/prepare-game-event.handler';
import { GamePrizeChanceIncreasedEventHandler } from './event-handlers/prize-chance-increased-event.handler';
import { GameGiveOutAPrizeCommandHandler } from './comand-handlers/give-out-a-prize-command.handler';
import { GameProceedGameQueueCommandHandler } from './comand-handlers/proceed-game-queue-command.handler';
import { GameWrongAnswerReceivedEventHandler } from './event-handlers/wrong-answer-received-event.handler';
import { GameController } from './game.controller';
import {ConfigService} from "@nestjs/config";
import {SelectTargetPlayerHandler} from "./comand-handlers/select-target-player.handler";
import {SendBetweenRoundsActionsHandler} from "../guests/command/send-between-rounds-actions.command";
import {GuestsModule} from "../guests/guests.module";
import { VersusService } from './versus/versus.service';
import { VersusController } from './versus/versus.controller';
import {Versus, VersusSchema} from "../schemas/versus.schema";
import {BeginVersusCommandHandler} from "./comand-handlers/begin-versus-command.handler";
import {CheckIfAnotherVersusInProgressHandler} from "./queries/handlers/check-if-another-versus-in-progress.handler";


const eventHandlers = [
  QuizAnsweredEventHandler,
  CardSelectionPendingEventHandler,
  PlayerCardSelectedEventHandler,
  GamePrepareGameEventHandler,
  GamePrizeChanceIncreasedEventHandler,
  GameGiveOutAPrizeCommandHandler,
  GameWrongAnswerReceivedEventHandler
];

const commandHandlers = [
  CreateNewQueueItemCommandHandler,
  GamePrizeChanceIncreasedEventHandler,
  GameProceedGameQueueCommandHandler,
  SelectTargetPlayerHandler,
  SendBetweenRoundsActionsHandler,
  BeginVersusCommandHandler,
];

const queryHandlers = [CheckIfAnotherVersusInProgressHandler];
@Global()
@Module({
  imports: [
    CqrsModule,
    MongooseModule.forFeature([
      { name: GameQueue.name, schema: GameQueueSchema },
      { name: Versus.name, schema: VersusSchema }
    ]),
    forwardRef(() => GuestsModule)
  ],
  providers: [GameService, ConfigService, ...eventHandlers, ...commandHandlers,...queryHandlers, VersusService],
  exports: [GameService],
  controllers: [GameController, VersusController],
})
export class GameModule {}
