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.UserInviteUserClientService;
import com.red.circle.other.infra.database.rds.service.user.user.UserInviteUserService;
import com.red.circle.other.inner.model.cmd.team.bd.BdTeamWorkStatisticsQryCmd;
import com.red.circle.other.inner.model.cmd.user.InviteStatisticsQryCmd;
import com.red.circle.other.inner.model.dto.user.UserInviteUserCountDTO;
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 UserInviteUserClientServiceImpl implements UserInviteUserClientService {

  private final UserInviteUserService userInviteUserService;

  @Override
  public Map<Long, UserInviteUserCountDTO> mapInviteStatisticsByUserIds(
      InviteStatisticsQryCmd qryCmd) {
    if (CollectionUtils.isEmpty(qryCmd.getUserIds())) {
      return Maps.newHashMap();
    }
    //获取bd邀请人数信息
    List<UserInviteUserCountDTO> dbUserInviteList = userInviteUserService.listInviteStatisticsByUserIds(
        qryCmd.getQryCmd(), qryCmd.getUserIds());
    if (CollectionUtils.isEmpty(dbUserInviteList)) {
      return Maps.newHashMap();
    }
    return dbUserInviteList.stream()
        .collect(Collectors.toMap(UserInviteUserCountDTO::getUserId, v -> v));
  }
}
