import {EventsHandler, IEventHandler} from "@nestjs/cqrs";
import {UserPropertyChangedEvent} from "../../../guests/event-handlers/user-property-changed.event";
import {SharedService} from "../../../shared/shared.service";
import {IUserPropertyChangedEvent} from "../../../Consts/types";
import {ClientNotificationType} from "../../socket.gateway";

@EventsHandler(UserPropertyChangedEvent)
export class UserPropertyChangedEventHandler implements IEventHandler<UserPropertyChangedEvent> {
  constructor(private sharedService: SharedService) {
  }
  handle(event: UserPropertyChangedEvent): void {
    this.sharedService.notifyAllClients<IUserPropertyChangedEvent>(ClientNotificationType.UserPropertyChanged, {
      user: event.user,
      property: event.property,
      value: event.propertyValue
    });
  }

}