import {EventsHandler, IEventHandler} from '@nestjs/cqrs';
import {CardsDealedEvent} from '../../../game/events/cards-dealed.event';
import {SharedService} from '../../../shared/shared.service';
import {IUserCardChangedEvent} from "../../../Consts/types";
import {ClientNotificationType} from "../../socket.gateway";

@EventsHandler(CardsDealedEvent)
export class CardsUpdatedEventHandler implements IEventHandler<CardsDealedEvent> {
  constructor(private sharedService: SharedService) {
  }
  handle(event: CardsDealedEvent): void {
    this.sharedService.notifyAllClients<IUserCardChangedEvent>(ClientNotificationType.CardsChanged, {
      telegramId: event.telegramId,
      cards: event.cards,
    });
  }
}
