package com.bonus.core.pay.channel.account.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import com.bonus.core.account.v3.api.vo.AccTradeOrderBalanceVO;
import com.bonus.core.account.v3.api.vo.AccTradeOrderWalletPayVO;
import com.bonus.core.account.v3.metadata.enums.AccWalletIdEnum;
import com.bonus.core.account.v3.web.vo.AccOrdBasicsVO;

import java.math.BigDecimal;

public class AccPayResultVO {
   private Long accTradeId;
   private BigDecimal accBal;
   private BigDecimal walletPay;
   private BigDecimal subsidyPay;
   private BigDecimal redEnvelopePay;
   private BigDecimal walletBal;
   private BigDecimal subBal;
   private BigDecimal redBal;
   private BigDecimal unpaidBalance;

   public int getWalletPayInt() {
      return NumberUtil.null2Zero(this.walletPay).intValue();
   }

   public int getSubsidyPayInt() {
      return NumberUtil.null2Zero(this.subsidyPay).intValue();
   }

   public int getRedEnvelopePayInt() {
      return NumberUtil.null2Zero(this.redEnvelopePay).intValue();
   }

   public int getWalletBalInt() {
      return NumberUtil.null2Zero(this.walletBal).intValue();
   }

   public int getSubBalInt() {
      return NumberUtil.null2Zero(this.subBal).intValue();
   }

   public int getRedBalInt() {
      return NumberUtil.null2Zero(this.redBal).intValue();
   }

   public int getAccBalInt() {
      return NumberUtil.null2Zero(this.accBal).intValue();
   }

   public int getUnpaidBalanceInt() {
      return NumberUtil.null2Zero(this.unpaidBalance).intValue();
   }

   public static AccPayResultVO of(AccOrdBasicsVO accOrdBasicsVO) {
      AccPayResultVO vo = new AccPayResultVO();
      vo.setAccTradeId(accOrdBasicsVO.getAccTradeId());
      vo.setAccBal(accOrdBasicsVO.getAccBal());
      vo.setWalletPay(accOrdBasicsVO.getWalletPay());
      vo.setSubsidyPay(accOrdBasicsVO.getSubsidyPay());
      vo.setRedEnvelopePay(accOrdBasicsVO.getRedEnvelopePay());
      vo.setWalletBal(accOrdBasicsVO.getWalletBal());
      vo.setSubBal(accOrdBasicsVO.getSubBal());
      vo.setRedBal(accOrdBasicsVO.getRedBal());
      vo.setUnpaidBalance(accOrdBasicsVO.getUnpaidBalance());
      return vo;
   }

   public static AccPayResultVO of(AccTradeOrderBalanceVO accTradeOrderBalanceVO) {
      if (accTradeOrderBalanceVO == null) {
         return null;
      } else {
         AccPayResultVO s = new AccPayResultVO();
         s.setAccBal(accTradeOrderBalanceVO.getWalletBalTotal());
         s.setAccTradeId(accTradeOrderBalanceVO.getAccTradeId());
         if (CollUtil.isNotEmpty(accTradeOrderBalanceVO.getWalletPayDetail())) {
            s.setWalletPay((BigDecimal)accTradeOrderBalanceVO.getWalletPayDetail().stream().filter((w) -> {
               return AccWalletIdEnum.WALLET.getKey().equals(w.getWalletId());
            }).map(AccTradeOrderWalletPayVO::getAmount).findFirst().orElse(BigDecimal.ZERO));
            s.setSubsidyPay((BigDecimal)accTradeOrderBalanceVO.getWalletPayDetail().stream().filter((w) -> {
               return AccWalletIdEnum.SUBSIDY.getKey().equals(w.getWalletId());
            }).map(AccTradeOrderWalletPayVO::getAmount).findFirst().orElse(BigDecimal.ZERO));
            s.setRedEnvelopePay((BigDecimal)accTradeOrderBalanceVO.getWalletPayDetail().stream().filter((w) -> {
               return AccWalletIdEnum.LUCK_MONEY.getKey().equals(w.getWalletId());
            }).map(AccTradeOrderWalletPayVO::getAmount).findFirst().orElse(BigDecimal.ZERO));
         }

         return s;
      }
   }

   public static AccPayResultVO ofBal(BigDecimal accBal, BigDecimal walletBal) {
      AccPayResultVO vo = new AccPayResultVO();
      vo.setAccBal(accBal);
      vo.setWalletBal(walletBal);
      return vo;
   }

   public static AccPayResultVO ofPay(BigDecimal walletPay, BigDecimal subsidyPay, BigDecimal redEnvelopePay) {
      AccPayResultVO vo = new AccPayResultVO();
      vo.setWalletPay(walletPay);
      vo.setSubsidyPay(subsidyPay);
      vo.setRedEnvelopePay(redEnvelopePay);
      return vo;
   }

   public Long getAccTradeId() {
      return this.accTradeId;
   }

   public BigDecimal getAccBal() {
      return this.accBal;
   }

   public BigDecimal getWalletPay() {
      return this.walletPay;
   }

   public BigDecimal getSubsidyPay() {
      return this.subsidyPay;
   }

   public BigDecimal getRedEnvelopePay() {
      return this.redEnvelopePay;
   }

   public BigDecimal getWalletBal() {
      return this.walletBal;
   }

   public BigDecimal getSubBal() {
      return this.subBal;
   }

   public BigDecimal getRedBal() {
      return this.redBal;
   }

   public BigDecimal getUnpaidBalance() {
      return this.unpaidBalance;
   }

   public void setAccTradeId(final Long accTradeId) {
      this.accTradeId = accTradeId;
   }

   public void setAccBal(final BigDecimal accBal) {
      this.accBal = accBal;
   }

   public void setWalletPay(final BigDecimal walletPay) {
      this.walletPay = walletPay;
   }

   public void setSubsidyPay(final BigDecimal subsidyPay) {
      this.subsidyPay = subsidyPay;
   }

   public void setRedEnvelopePay(final BigDecimal redEnvelopePay) {
      this.redEnvelopePay = redEnvelopePay;
   }

   public void setWalletBal(final BigDecimal walletBal) {
      this.walletBal = walletBal;
   }

   public void setSubBal(final BigDecimal subBal) {
      this.subBal = subBal;
   }

   public void setRedBal(final BigDecimal redBal) {
      this.redBal = redBal;
   }

   public void setUnpaidBalance(final BigDecimal unpaidBalance) {
      this.unpaidBalance = unpaidBalance;
   }
}
