import {EventsHandler, IEventHandler} from '@nestjs/cqrs';
import {ValidAnswerReceivedEvent} from '../../../game/events/valid-answer.recieved';
import {SharedService} from '../../../shared/shared.service';
import {ClientNotificationType} from "../../socket.gateway";
import {IValidAnswerReceivedSocketEvent} from "../../../Consts/types";

@EventsHandler(ValidAnswerReceivedEvent)
export class SocketValidAnswerReceivedEventHandler
  implements IEventHandler<ValidAnswerReceivedEvent> {

  constructor(private sharedService: SharedService) {
  }

  handle(event: ValidAnswerReceivedEvent): any {
    const notification : IValidAnswerReceivedSocketEvent  = {
      telegramId: event.tId,
      validAnswer: event.validAnswer,
      note: event.extraDetails
    };
    this.sharedService
      .notifyAllClients<IValidAnswerReceivedSocketEvent>(ClientNotificationType.ValidAnswerReceived, notification);
  }
}
