package com.red.circle.other.app.inner.service.user.user.impl;

import com.google.common.collect.Maps;
import com.red.circle.other.app.inner.service.user.user.UserRechargeCoinsClientService;
import com.red.circle.other.infra.database.rds.service.user.user.UserGoldCoinRechargeService;
import com.red.circle.other.inner.model.cmd.user.InviteStatisticsQryCmd;
import com.red.circle.other.inner.model.dto.user.UserGoldCoinRechargeDTO;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 * 用户充值服务
 *
 * @author xiongcheng on 2024/3/8
 */
@Service
@RequiredArgsConstructor
public class UserRechargeCoinsClientServiceImpl implements UserRechargeCoinsClientService {

  private final UserGoldCoinRechargeService userGoldCoinRechargeService;

  @Override
  public Map<Long, List<UserGoldCoinRechargeDTO>> mapRechargeCoinsByUserIds(Set<Long> userIds) {
    if (CollectionUtils.isEmpty(userIds)) {
      return Maps.newHashMap();
    }
    //获取用户充值记录
    List<UserGoldCoinRechargeDTO> userGoldCoinRechargeList = userGoldCoinRechargeService.listRechargeCoinsByUserIds(
        userIds);
    if (CollectionUtils.isEmpty(userGoldCoinRechargeList)) {
      return Maps.newHashMap();
    }
    return userGoldCoinRechargeList.stream().collect(Collectors.groupingBy(UserGoldCoinRechargeDTO::getUserId));
  }

  @Override
  public Map<Long, BigDecimal> mapGoldCoinRechargeByUserIds(InviteStatisticsQryCmd qryCmd) {
    if (CollectionUtils.isEmpty(qryCmd.getUserIds())) {
      return Maps.newHashMap();
    }
    //获取bd邀请总充值
    Map<Long, BigDecimal> userGoldCoinRechargeMap=userGoldCoinRechargeService.mapGoldCoinRechargeByUserIds(qryCmd);
    if (CollectionUtils.isEmpty(userGoldCoinRechargeMap)) {
      return Maps.newHashMap();
    }
    return userGoldCoinRechargeMap;
  }
}
