package com.red.circle.other.app.listener;

import com.red.circle.component.mq.MessageEventProcess;
import com.red.circle.component.mq.MessageEventProcessDescribe;
import com.red.circle.component.mq.config.RocketMqMessageListener;
import com.red.circle.component.mq.service.Action;
import com.red.circle.component.mq.service.ConsumerMessage;
import com.red.circle.component.mq.service.MessageListener;
import com.red.circle.mq.business.model.event.game.GameRoomVoteEvent;
import com.red.circle.mq.rocket.business.streams.GameRoomVoteSink;
import com.red.circle.other.app.common.game.GameRoomVoteCommon;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 投票游戏.
 *
 * @author pengshigang on 2022/01/07
 */
@Slf4j
@RocketMqMessageListener(topic = "${rocketmq.topics.RC_DEFAULT_APP_DELAYED}", groupId = GameRoomVoteSink.INPUT, tag = GameRoomVoteSink.TAG)
@RequiredArgsConstructor
public class GameRoomVoteListener implements MessageListener {

  private final GameRoomVoteCommon gameRoomVoteCommon;
  private final MessageEventProcess messageEventProcess;

  @Override
  public Action consume(ConsumerMessage message) {
    return messageEventProcess.consume(
        MessageEventProcessDescribe.builder()
            .logTag("投票游戏")
            .consumeMsgTimeoutMinute(60 * 3)
            .repeatConsumeTag("GameRoomVote")
            .checkConsumeTag(GameRoomVoteSink.TAG)
            .message(message)
            .build(),
        GameRoomVoteEvent.class,
        gameRoomVoteCommon::processGame);
  }

}
