import {EventsHandler, IEventHandler} from '@nestjs/cqrs';
import {ScoreChangedEvent} from '../../../game/events/score-changed.event';
import {SharedService} from '../../../shared/shared.service';
import {IScoreChangedSocketEvent} from "../../../Consts/types";
import {ClientNotificationType} from "../../socket.gateway";

@EventsHandler(ScoreChangedEvent)
export class SocketScoreChangedEventHandler
  implements IEventHandler<ScoreChangedEvent> {
  constructor(private sharedService: SharedService) {
  }
  async handle(event: ScoreChangedEvent) {
    this.sharedService.notifyAllClients<IScoreChangedSocketEvent>(ClientNotificationType.ScoreChanged, {
      telegramId: event.telegramId,
      newScore: event.newScore,
    });
  }
}
