import {CommandBus, CommandHandler, ICommandHandler} from "@nestjs/cqrs";
import {RemoveCardFromUserCommand} from "../../game/commands/remove-card-from-user.command";
import {GuestsService} from "../guests.service";
import {SharedService} from "../../shared/shared.service";
import {Inject} from "@nestjs/common";
import {ClientProxy} from "@nestjs/microservices";
import {CommandsConsts} from "../../Consts/commands.consts";
import {MqtMessageModel} from "../../messaging/models/mqt-message.model";
import {ChatMessageRequestModel} from "../../messaging/models/chat-message-request.model";
import {Messages} from "../../messaging/tg.text";

@CommandHandler(RemoveCardFromUserCommand)
export class RemoveCardFromUserCommandHandler implements ICommandHandler<RemoveCardFromUserCommand> {
  constructor(
    private guestService: GuestsService,
    private sharedService: SharedService,
    @Inject('Telegram') private telegramService: ClientProxy,
    private cmdBus: CommandBus,
  ) {
  }

  async execute(command: RemoveCardFromUserCommand): Promise<any> {
    // const guest = await this.guestService.findById(command.telegramId);
    // const data = await this.sharedService.getConfig(`buttons_${command.telegramId}`);
    // const extra = {
    //   reply_markup: {
    //     remove_keyboard: false,
    //     keyboard: [],
    //   },
    // };
    // const buttons = JSON.parse(data.value);
    // let found = false;
    // buttons.reply_markup.keyboard.forEach((item) => {
    //   if (item[0].text.includes(command.card.description) && !found) {
    //     found = true;
    //   } else {
    //     extra.reply_markup.keyboard.push(
    //       [ { ...item[0] } ]
    //     )
    //   }
    // });
    // if (extra.reply_markup.keyboard.length === 0) {
    //   extra.reply_markup.remove_keyboard = true;
    // }
    // await this.sharedService.setConfig(`buttons_${command.telegramId}`, JSON.stringify(extra));
    // this.telegramService.emit<MqtMessageModel, ChatMessageRequestModel>({
    //   cmd: CommandsConsts.SendMessage,
    // }, {
    //   chatId: guest.chatId,
    //   message: Messages.SELECT_CARD,
    //   extra: extra,
    // })

  }
}