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.component.mq.service.SenderService;
import com.red.circle.mq.business.model.event.gift.GiveAwayGiftBatchEvent;
import com.red.circle.mq.business.model.event.gift.OfflineProcessGiftEvent;
import com.red.circle.mq.rocket.business.streams.GiveGiftSink;
import com.red.circle.mq.rocket.business.streams.OfflineProcessGiftSink;
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 礼物相关.
 *
 * @author pengliang on 2023/9/25
 */
@Component
@RequiredArgsConstructor
public class GiftMqMessage {

  private final SenderService senderService;


  /**
   * 赠送礼物.
   */
  public void sendGift(String consumeId, GiveAwayGiftBatchEvent event) {
    event.setCreateDateRiyadhNum(ZonedDateTimeAsiaRiyadhUtils.nowDateToInt());

    senderService.sendEventMessage(MessageEvent.builder()
        .consumeId(consumeId)
        .topic(FixedTopic.RC_DEFAULT_APP_ORDINARY)
        .tag(GiveGiftSink.TAG)
        .body(event)
        .build());

  }

  /**
   * 赠送礼物-离线计算.
   */
  public void sendOfflineProcessGiftEvent(OfflineProcessGiftEvent event) {
    senderService.sendEventMessage(MessageEvent.builder()
        .consumeId(event.getType() + "_" + event.getRunningWaterId())
        .topic(FixedTopic.RC_DEFAULT_APP_ORDINARY)
        .tag(OfflineProcessGiftSink.TAG)
        .body(event)
        .build());
  }

}
