import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { CreateNewQueueItemCommand } from '../commands/create-new-queue-item.command';
import { GameService } from '../game.service';
import {Logger} from "@nestjs/common";

@CommandHandler(CreateNewQueueItemCommand)
export class CreateNewQueueItemCommandHandler implements ICommandHandler<CreateNewQueueItemCommand> {
  private logger = new Logger(CreateNewQueueItemCommandHandler.name);
  constructor(
    private gameService: GameService,

  ) {
  }

  async execute(command: CreateNewQueueItemCommand): Promise<any> {
    this.logger.verbose(`Adding new queue item ${command.type} for ${command.target}`);
    await this.gameService.addTaskToGameQueue(command.target, command.type, command.text);
    return Promise.resolve(undefined);
  }

}
