package com.red.circle.mq.rocket.business.producer;

import com.red.circle.component.mq.MessageEvent;
import com.red.circle.component.mq.service.FixedTopic;
import com.red.circle.mq.business.model.event.room.LiveVoiceSessionEvent;
import com.red.circle.mq.business.model.event.room.RoomVoiceCreateSuccessEvent;
import com.red.circle.mq.rocket.business.service.MessageSenderService;
import com.red.circle.mq.rocket.business.streams.CreateRoomSuccessSink;
import com.red.circle.mq.rocket.business.streams.LiveVoiceSessionSink;
import com.red.circle.tool.core.sequence.IdWorkerUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 房间相关mq消息.
 *
 * @author pengliang on 2021/4/8
 */
@Component
@RequiredArgsConstructor
public class RoomMqMessageService {

  private final MessageSenderService messageSenderService;

  /**
   * 创建语音房间成功.
   */
  public void createVoiceRoomSuccess(RoomVoiceCreateSuccessEvent event) {
    messageSenderService.sendEventMessage(MessageEvent.builder()
        .consumeId(event.getId().toString())
        .topic(FixedTopic.RC_DEFAULT_APP_ORDINARY)
        .tag(CreateRoomSuccessSink.TAG)
        .body(event)
        .build());
  }

  /**
   * 直播会话连接.
   */
  public void liveSessionConnection(LiveVoiceSessionEvent event) {
    messageSenderService.sendEventMessage(MessageEvent.builder()
        .consumeId(IdWorkerUtils.getIdStr())
        .topic(FixedTopic.RC_DEFAULT_APP_ORDINARY)
        .tag(LiveVoiceSessionSink.TAG)
        .body(event)
        .build());
  }

}
