package com.red.circle.console.app.service.app.activity;

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.common.business.enums.SendPropsOrigin;
import com.red.circle.console.app.dto.cmd.app.activity.invite.InviteCampaignGrantGoldCmd;
import com.red.circle.console.app.dto.cmd.app.activity.invite.InviteCampaignGrantPropsCmd;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.other.inner.endpoint.activity.PropsActivityClient;
import com.red.circle.other.inner.model.cmd.activity.SendActivityRewardCmd;
import com.red.circle.tool.core.tuple.PennyAmount;
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd;
import com.red.circle.wallet.inner.model.enums.GoldOrigin;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 邀请活动奖励桥接服务实现.
 */
@Service
@RequiredArgsConstructor
public class ResidentInviteActivityRewardBridgeServiceImpl
    implements ResidentInviteActivityRewardBridgeService {

  private final WalletGoldClient walletGoldClient;
  private final PropsActivityClient propsActivityClient;

  @Override
  public void grantGold(InviteCampaignGrantGoldCmd cmd) {
    ResponseAssert.requiredSuccess(walletGoldClient.changeBalance(
        GoldReceiptCmd.builder()
            .userId(cmd.getUserId())
            .sysOrigin(cmd.getSysOrigin())
            .eventId(cmd.getEventId())
            .origin(GoldOrigin.valueOf(cmd.getOrigin()))
            .remark(cmd.getRemark())
            .amount(PennyAmount.ofDollar(cmd.getGoldAmount()))
            .appIncome()
            .build()));
  }

  @Override
  public void grantProps(InviteCampaignGrantPropsCmd cmd) {
    ResponseAssert.requiredSuccess(propsActivityClient.sendActivityReward(
        new SendActivityRewardCmd()
            .setTrackId(cmd.getTrackId())
            .setOrigin(SendPropsOrigin.valueOf(cmd.getOrigin()))
            .setSysOrigin(SysOriginPlatformEnum.valueOf(cmd.getSysOrigin()))
            .setSourceGroupId(cmd.getSourceGroupId())
            .setAcceptUserId(cmd.getAcceptUserId())));
  }
}
