package com.red.circle.other.app.command.game.turntable;

import com.red.circle.other.app.dto.cmd.game.GameTurntableProcessingStatusCmd;
import com.red.circle.other.infra.database.mongo.service.game.RoomTurntableGameMongoService;
import com.red.circle.other.infra.enums.game.TurntableGameStatus;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 游戏进行中的状态.
 *
 * @author pengliang on 2021/3/19
 */
@Component
@RequiredArgsConstructor
public class GameTurntableProcessingStatusCmdExe {

  private final RoomTurntableGameMongoService roomTurntableGameMongoService;

  public void execute(GameTurntableProcessingStatusCmd cmd) {
    if (Objects.nonNull(cmd.getWeedOutUserId()) && cmd.getWeedOutUserId() > 0) {
      roomTurntableGameMongoService.weedOut(cmd.getGameId(), cmd.getWeedOutUserId());
      return;
    }

    if (Objects.nonNull(cmd.getJackpotUserId()) && cmd.getJackpotUserId() > 0) {
      roomTurntableGameMongoService.jackpot(cmd.getGameId(), cmd.getWeedOutUserId());
      roomTurntableGameMongoService
          .updateGameStatus(cmd.getGameId(), TurntableGameStatus.COMPLETE.name());
    }
  }

}
