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

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.infra.database.rds.service.user.user.ConsumptionLevelService;
import com.red.circle.other.app.inner.convertor.user.UserProfileInnerConvertor;
import com.red.circle.other.inner.model.dto.user.WealthAndCharmExpLevelDTO;
import com.red.circle.other.app.inner.service.user.user.UserLevelClientService;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 用户等级，服务 实现.
 *
 * @author pengliang on 2023/6/3
 */
@Service
@RequiredArgsConstructor
public class UserLevelClientServiceImpl implements UserLevelClientService {

  private final UserProfileGateway userProfileGateway;
  private final ConsumptionLevelService consumptionLevelService;
  private final UserProfileInnerConvertor userProfileInnerConvertor;

  @Override
  public WealthAndCharmExpLevelDTO getUserLevelExp(SysOriginPlatformEnum sysOrigin, Long userId) {
    return userProfileInnerConvertor.toWealthAndCharmExpLevelDTO(
        userProfileGateway.getUserConsumptionLevel(sysOrigin, userId));
  }

  @Override
  public List<WealthAndCharmExpLevelDTO> getUsersLevelExp(SysOriginPlatformEnum sysOrigin, List<Long> userIds) {
    List<WealthAndCharmExpLevelDTO> wealth = new ArrayList<>();
    for (Long id : userIds) {
      WealthAndCharmExpLevelDTO wealthAndCharmExpLevelDTO = getUserLevelExp(sysOrigin, id);
      wealthAndCharmExpLevelDTO.setUserId(id);
      wealth.add(wealthAndCharmExpLevelDTO);
    }
    return wealth;
  }

  @Override
  public void incrWealthExp(Long userId, BigDecimal quantity) {
    consumptionLevelService.incrConsumptionGolds(userId, quantity);
  }

  @Override
  public BigDecimal getWealthExp(Long userId) {
    return consumptionLevelService.getConsumptionGolds(userId);
  }

  @Override
  public void incrCharmExp(Long userId, BigDecimal quantity) {
    consumptionLevelService.incrConsumptionDiamond(userId, quantity);
  }

  @Override
  public BigDecimal getCharmExp(Long userId) {
    return consumptionLevelService.getConsumptionDiamond(userId);
  }

}
