package com.red.circle.order.infra.gateway;

import com.red.circle.order.domain.gateway.UserRechargeCountGateway;
import com.red.circle.order.infra.database.rds.service.count.MonthlyRechargeUserService;
import com.red.circle.order.infra.database.rds.service.count.TotalRechargeService;
import com.red.circle.order.infra.database.rds.service.count.TotalRechargeUserService;
import com.red.circle.order.infra.database.rds.service.count.UserMonthlyRechargeService;
import com.red.circle.order.inner.model.cmd.UserRechargeMonthQryCmd;
import com.red.circle.order.inner.model.dto.MonthlyRechargeUserDTO;
import com.red.circle.order.inner.model.dto.TotalRechargeUserDTO;
import com.red.circle.order.inner.model.enums.MonthlyRechargeType;
import java.math.BigDecimal;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author pengliang on 2022/5/27
 */
@Component
@RequiredArgsConstructor
public class UserRechargeCountGatewayImpl implements UserRechargeCountGateway {

  private final TotalRechargeService totalRechargeService;
  private final TotalRechargeUserService totalRechargeUserService;
  private final MonthlyRechargeUserService monthlyRechargeUserService;
  private final UserMonthlyRechargeService userMonthlyRechargeService;

  @Override
  public List<MonthlyRechargeUserDTO> listMonthlyRecharge(UserRechargeMonthQryCmd cmd) {
    return monthlyRechargeUserService.listMonthlyRecharge(cmd);
  }

  @Override
  public List<TotalRechargeUserDTO> listUserRechargeTotal(String sysOrigin) {
    return totalRechargeUserService.listUserRechargeTotal(sysOrigin);
  }

  @Override
  public void count(Long userId, BigDecimal amount, MonthlyRechargeType type) {
    userMonthlyRechargeService.incrThisMonthAmount(userId, amount, type);
    totalRechargeService.incrAmount(userId, amount, type);
    monthlyRechargeUserService.incAmount(userId, amount);
    totalRechargeUserService.incAmount(userId, amount);

  }

  @Override
  public void decr(Long userId, BigDecimal amount, MonthlyRechargeType type) {
    userMonthlyRechargeService.decrThisMonthAmount(userId, amount, type);
    totalRechargeService.decr(userId, amount, type);
    monthlyRechargeUserService.decr(userId, amount);
    totalRechargeUserService.decr(userId, amount);

  }

}
