package com.red.circle.wallet.inner.service.diamond.impl;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.wallet.infra.database.rds.entity.diamond.SalaryDiamondBalance;
import com.red.circle.wallet.infra.database.rds.service.diamond.SalaryDiamondBalanceService;
import com.red.circle.wallet.inner.convertor.SalaryDiamondBalanceInnerConvertor;
import com.red.circle.wallet.inner.model.cmd.UserSalaryDiamondBalanceQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserSalaryDiamondCmd;
import com.red.circle.wallet.inner.model.dto.SalaryDiamondBalanceDTO;
import com.red.circle.wallet.inner.service.diamond.SalaryDiamondBalanceClientService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 用户工资钻石
 *
 * @author zongpubin on 2024/3/14
 */
@Service
@RequiredArgsConstructor
public class SalaryDiamondBalanceClientServiceImpl implements SalaryDiamondBalanceClientService {

  private final SalaryDiamondBalanceService salaryDiamondBalanceService;
  private final SalaryDiamondBalanceInnerConvertor salaryDiamondBalanceInnerConvertor;

  @Override
  public PageResult<SalaryDiamondBalanceDTO> listUserSalaryDiamondBalance(
      UserSalaryDiamondBalanceQryCmd query) {
    return salaryDiamondBalanceService.listUserSalaryDiamondBalance(
        query).convert(salaryDiamondBalanceInnerConvertor::toSalaryDiamondBalanceDTO);
  }

  @Override
  public boolean exists(Long userId) {
    return salaryDiamondBalanceService.exists(userId);
  }

  @Override
  public boolean incr(UserSalaryDiamondCmd param) {
    return salaryDiamondBalanceService.incr(param);
  }

  @Override
  public SalaryDiamondBalanceDTO getBalance(Long userId) {
    return salaryDiamondBalanceInnerConvertor.toSalaryDiamondBalanceDTO(
        salaryDiamondBalanceService.getBalance(userId));
  }

  @Override
  public SalaryDiamondBalanceDTO decr(UserSalaryDiamondCmd param) {
    return salaryDiamondBalanceInnerConvertor.toSalaryDiamondBalanceDTO(
        salaryDiamondBalanceService.decr(param));
  }

  @Override
  public Map<Long, BigDecimal> mapBalanceBySysOrigin(String sysOrigin) {
    return salaryDiamondBalanceService.mapBalanceBySysOrigin(sysOrigin);
  }

}
