package com.red.circle.wallet.app.service;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.wallet.app.command.salary.SalaryExchangeGoldCmdExe;
import com.red.circle.wallet.app.command.salary.SalaryIssueCmdExe;
import com.red.circle.wallet.app.command.salary.SalaryTransferGoldCmdExe;
import com.red.circle.wallet.app.command.salary.SalaryWithdrawRefundCmdExe;
import com.red.circle.wallet.app.command.salary.query.SalaryAccountBalanceQryExe;
import com.red.circle.wallet.app.command.salary.query.SalaryRunningWaterQryExe;
import com.red.circle.wallet.app.command.salary.query.SalaryTotalIncomeQryExe;
import com.red.circle.wallet.app.dto.clientobject.*;
import com.red.circle.wallet.app.dto.cmd.*;
import com.red.circle.wallet.domain.salary.SalaryType;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * 工资账户服务实现.
 */
@Service
@RequiredArgsConstructor
public class SalaryAccountServiceImpl implements SalaryAccountService {

  private final SalaryAccountBalanceQryExe salaryAccountBalanceQryExe;
  private final SalaryRunningWaterQryExe salaryRunningWaterQryExe;
  private final SalaryIssueCmdExe salaryIssueCmdExe;
  private final SalaryWithdrawRefundCmdExe salaryWithdrawRefundCmdExe;
  private final SalaryExchangeGoldCmdExe salaryExchangeGoldCmdExe;
  private final SalaryTransferGoldCmdExe salaryTransferGoldCmdExe;
  private final SalaryTotalIncomeQryExe salaryTotalIncomeQryExe;

  @Override
  public SalaryAccountBalanceCO getBalance(Long userId, String salaryType) {
    return salaryAccountBalanceQryExe.execute(userId, SalaryType.of(salaryType));
  }

  @Override
  public SalaryIssueResultCO issueSalary(SalaryIssueCmd cmd) {
    return salaryIssueCmdExe.execute(cmd);
  }

  @Override
  public void withdrawRefund(SalaryWithdrawCmd cmd) {
    salaryWithdrawRefundCmdExe.execute(cmd);
  }

  @Override
  public PageResult<SalaryRunningWaterCO> queryRunningWater(SalaryRunningWaterQueryCmd cmd) {
    return salaryRunningWaterQryExe.execute(cmd);
  }

    @Override
    public UserBankWithdrawResultCO transferGold(SalaryWithdrawCmd cmd) {
        return salaryTransferGoldCmdExe.execute(cmd);
    }

    @Override
    public UserBankExchangeGoldResultCO exchangeGold(SalaryWithdrawCmd cmd) {
        return salaryExchangeGoldCmdExe.execute(cmd);
    }

    @Override
    public BigDecimal getTotalIncome(Long userId, String salaryType) {
        return salaryTotalIncomeQryExe.execute(userId, Objects.requireNonNull(SalaryType.of(salaryType)));
    }
}
