import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { SendToastCommand } from '../../../game/commands/send-toast.command';
import { SharedService } from '../../../shared/shared.service';
import { SocketEvents } from '../../../shared/events.consts';
import {Logger} from "@nestjs/common";

@CommandHandler(SendToastCommand)
export class SendToastCommandHandler implements ICommandHandler<SendToastCommand> {
  private readonly logger = new Logger(SendToastCommand.name);
  constructor(private sharedService: SharedService) {
  }
  async execute(command: SendToastCommand) {
    this.logger.verbose(`send notification: ${command.text}`);
    await this.sharedService.sendSocketNotificationToAllClients(
      SocketEvents.NOTIFICATION,
      {
        text: command.text,
        timeout: command.timeout,
      },
    );
  }
}
