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.GameIndoorTeamPkEvent;
import com.red.circle.mq.rocket.business.streams.GameIndoorTeamPkSink;
import com.red.circle.other.app.common.game.GameIndoorTeamPkCommon;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 游戏房间内团队pk.
 *
 * @author pengshigang on 2022/03/04
 */
@Slf4j
@RocketMqMessageListener(topic = "${rocketmq.topics.RC_DEFAULT_APP_DELAYED}", groupId = GameIndoorTeamPkSink.INPUT, tag = GameIndoorTeamPkSink.TAG)
@RequiredArgsConstructor
public class GameIndoorTeamPkListener implements MessageListener {

  private final MessageEventProcess messageEventProcess;
  private final GameIndoorTeamPkCommon gameIndoorTeamPkCommon;

  @Override
  public Action consume(ConsumerMessage message) {
    return messageEventProcess.consume(
        MessageEventProcessDescribe.builder()
            .logTag("房间团队PK")
            .consumeMsgTimeoutMinute(60 * 3)
            .repeatConsumeMinute(1)
            .repeatConsumeTag("GameIndoorTeamPk")
            .checkConsumeTag(GameIndoorTeamPkSink.TAG)
            .message(message)
            .build(),
        GameIndoorTeamPkEvent.class,
        gameIndoorTeamPkCommon::processRoomPk);
  }

}
