import {EventsHandler, IEventHandler} from '@nestjs/cqrs';
import {UserRegisteredEvent} from '../../../game/events/user-registered.event';
import {SharedService} from '../../../shared/shared.service';
import {IUserBasicInfo} from "../../../Consts/types";
import {ClientNotificationType} from "../../socket.gateway";

@EventsHandler(UserRegisteredEvent)
export class UserRegisteredEventHandler implements IEventHandler<UserRegisteredEvent> {
  constructor(private sharedService: SharedService) {
  }
  handle(event: UserRegisteredEvent): void {
    this.sharedService.notifyAllClients<IUserBasicInfo>(ClientNotificationType.UserAdded, {
      telegramId: event.telegramId,
      name: event.name,
    });
  }
}
