import {CommandHandler, ICommandHandler} from "@nestjs/cqrs";
import {IncreasePlayerScoreCommand} from "../increase-player-score.command";
import { Logger } from "@nestjs/common";
import {GuestsService} from "../../guests.service";

@CommandHandler(IncreasePlayerScoreCommand)
export class IncreasePlayerScoreCommandHandler implements ICommandHandler<IncreasePlayerScoreCommand> {
  private logger = new Logger(IncreasePlayerScoreCommandHandler.name);
  constructor(private guestService: GuestsService) {
  }


  async execute(command: IncreasePlayerScoreCommand): Promise<any> {
        this.logger.verbose(`IncreasePlayerScoreCommandHandler: entering, arguments: player: ${command.user}, amount: ${command.score}`);
        await this.guestService.updatePlayerScore(command.user, command.score);
        return true;
    }

}