import {CommandHandler, ICommandHandler} from '@nestjs/cqrs';
import {NotifyCardOnScreenCommand} from '../../../game/commands/notify-card-on-screen-command';
import {SharedService} from '../../../shared/shared.service';
import {Logger} from '@nestjs/common';
import {ICardPlayedSocketEvent} from "../../../Consts/types";
import {ClientNotificationType} from "../../socket.gateway";

@CommandHandler(NotifyCardOnScreenCommand)
export class NotifyCardPlayedCommandHandler
  implements ICommandHandler<NotifyCardOnScreenCommand> {
  private logger = new Logger(NotifyCardPlayedCommandHandler.name);
  constructor(private sharedService: SharedService) {
  }
  async execute(command: NotifyCardOnScreenCommand): Promise<any> {
    this.logger.log(`Notify about card`);
    this.sharedService.notifyAllClients<ICardPlayedSocketEvent>(ClientNotificationType.CardPlayed, {
      telegramId: command.telegramId,
      card: command.card.description,
      name: command.card.name,
      timeout: command.timeToShow
    });
    return true;
  }
}
