package com.red.circle.other.app.command.activity;

import com.google.common.collect.Lists;
import com.red.circle.other.app.dto.clientobject.activity.InviteUserCommissionDetailsCO;
import com.red.circle.other.app.dto.cmd.activity.InviteUserActivityLimitCmd;
import com.red.circle.other.infra.database.rds.entity.user.user.InviteUserRechargeCommission;
import com.red.circle.other.infra.database.rds.service.user.user.InviteUserRechargeCommissionService;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.num.NumUtils;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 邀请用户注册活动 佣金明细.
 *
 * @author pengshigang
 * @since 2022-05-24
 */
@Component
@RequiredArgsConstructor
public class InviteUserCommissionDetailsExe {

  private final InviteUserRechargeCommissionService rechargeCommissionService;

  public List<InviteUserCommissionDetailsCO> execute(InviteUserActivityLimitCmd cmd) {

    List<InviteUserRechargeCommission> page = rechargeCommissionService
        .pageByCommissionDesc(cmd.getPageNumber(), cmd.getInviteUserId());

    if (CollectionUtils.isEmpty(page)) {
      return Lists.newArrayList();
    }
    return page.stream().map(commission -> new InviteUserCommissionDetailsCO()
        .setUserId(commission.getUserId())
        .setTotalCommission(NumUtils.formatBigDecimal(commission.getCommission()))
        .setCreateTime(commission.getCreateTime())
    ).toList();
  }

}
