package com.bonus.core.pay.common.dto;

import cn.hutool.core.collection.CollUtil;
import com.bonus.core.common.utils.JacksonUtil;
import com.bonus.core.pay.api.dto.UnifyRefundDTO;
import com.bonus.core.pay.common.constants.PayChannelEnum;
import com.bonus.core.pay.common.constants.PayStateEnum;
import com.bonus.core.pay.common.model.TradeChannel;
import com.bonus.core.pay.common.vo.TradeChannelVO;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

public class PayRefundDTO {
   /** @deprecated */
   @Deprecated
   private Long tradeId;
   private Long tradeChannelId;
   /** @deprecated */
   @Deprecated
   private Long refundTradeId;
   private Long refundTradeChannelId;
   private BigDecimal refundAmount;
   private Integer tradeType;
   private Long custId;
   private String custThirdId;
   private Long canteenId;
   private String canteenName;
   private Long stallId;
   private String stallName;
   private String machineSn;
   private String macOrderId;
   private LocalDateTime tradeTime;
   private LocalDateTime refundTradeTime;
   private String outTradeNo;
   private BigDecimal amount;
   private Integer payType;
   private Integer payChannel;
   private Integer nuClearMode;
   private List<UnifyRefundDTO.WalletDetail> walletDetailList =
           CollUtil.newArrayList(new UnifyRefundDTO.WalletDetail[0]);
   private List<UnifyRefundDTO.Detail> refundDetailList = CollUtil.newArrayList(new UnifyRefundDTO.Detail[0]);

   /** @deprecated */
   @Deprecated
   public Long getRefundTradeId() {
      return this.refundTradeChannelId;
   }

   /** @deprecated */
   public Long getTradeId() {
      return this.tradeChannelId;
   }

   public boolean couldSkipChannelRefund() {
      return this.getAmount().intValue() == 0 && !PayChannelEnum.ACC.getKey().equals(this.getPayChannel()) && !PayChannelEnum.THIRD.getKey().equals(this.getPayChannel()) && !PayChannelEnum.COUPON.getKey().equals(this.getPayChannel());
   }

   public TradeChannel convertToTradeChannel(TradeChannelVO originalTradeChannel, Long refundTradeId) {
      TradeChannel tradeChannel = new TradeChannel();
      tradeChannel.setTradeId(refundTradeId);
      tradeChannel.setTradeChannelId(this.refundTradeChannelId);
      tradeChannel.setAmount(this.refundAmount);
      tradeChannel.setTradeState(PayStateEnum.PAY_INPROCESS.getKey());
      tradeChannel.setTradeResult(PayStateEnum.PAY_INPROCESS.getDesc());
      tradeChannel.setPayType(originalTradeChannel.getPayType());
      tradeChannel.setPayChannel(originalTradeChannel.getPayChannel());
      tradeChannel.setParam(JacksonUtil.objectNode().put("originalTradeChannelId", originalTradeChannel.getTradeChannelId()));
      return tradeChannel;
   }

   public static PayRefundDTO of(Long refundTradeId) {
      PayRefundDTO payRefundDTO = new PayRefundDTO();
      payRefundDTO.setRefundTradeId(refundTradeId);
      return payRefundDTO;
   }

   public Long getTradeChannelId() {
      return this.tradeChannelId;
   }

   public Long getRefundTradeChannelId() {
      return this.refundTradeChannelId;
   }

   public BigDecimal getRefundAmount() {
      return this.refundAmount;
   }

   public Integer getTradeType() {
      return this.tradeType;
   }

   public Long getCustId() {
      return this.custId;
   }

   public String getCustThirdId() {
      return this.custThirdId;
   }

   public Long getCanteenId() {
      return this.canteenId;
   }

   public String getCanteenName() {
      return this.canteenName;
   }

   public Long getStallId() {
      return this.stallId;
   }

   public String getStallName() {
      return this.stallName;
   }

   public String getMachineSn() {
      return this.machineSn;
   }

   public String getMacOrderId() {
      return this.macOrderId;
   }

   public LocalDateTime getTradeTime() {
      return this.tradeTime;
   }

   public LocalDateTime getRefundTradeTime() {
      return this.refundTradeTime;
   }

   public String getOutTradeNo() {
      return this.outTradeNo;
   }

   public BigDecimal getAmount() {
      return this.amount;
   }

   public Integer getPayType() {
      return this.payType;
   }

   public Integer getPayChannel() {
      return this.payChannel;
   }

   public Integer getNuClearMode() {
      return this.nuClearMode;
   }

   public List<UnifyRefundDTO.WalletDetail> getWalletDetailList() {
      return this.walletDetailList;
   }

   public List<UnifyRefundDTO.Detail> getRefundDetailList() {
      return this.refundDetailList;
   }

   /** @deprecated */
   @Deprecated
   public void setTradeId(final Long tradeId) {
      this.tradeId = tradeId;
   }

   public void setTradeChannelId(final Long tradeChannelId) {
      this.tradeChannelId = tradeChannelId;
   }

   /** @deprecated */
   @Deprecated
   public void setRefundTradeId(final Long refundTradeId) {
      this.refundTradeId = refundTradeId;
   }

   public void setRefundTradeChannelId(final Long refundTradeChannelId) {
      this.refundTradeChannelId = refundTradeChannelId;
   }

   public void setRefundAmount(final BigDecimal refundAmount) {
      this.refundAmount = refundAmount;
   }

   public void setTradeType(final Integer tradeType) {
      this.tradeType = tradeType;
   }

   public void setCustId(final Long custId) {
      this.custId = custId;
   }

   public void setCustThirdId(final String custThirdId) {
      this.custThirdId = custThirdId;
   }

   public void setCanteenId(final Long canteenId) {
      this.canteenId = canteenId;
   }

   public void setCanteenName(final String canteenName) {
      this.canteenName = canteenName;
   }

   public void setStallId(final Long stallId) {
      this.stallId = stallId;
   }

   public void setStallName(final String stallName) {
      this.stallName = stallName;
   }

   public void setMachineSn(final String machineSn) {
      this.machineSn = machineSn;
   }

   public void setMacOrderId(final String macOrderId) {
      this.macOrderId = macOrderId;
   }

   public void setTradeTime(final LocalDateTime tradeTime) {
      this.tradeTime = tradeTime;
   }

   public void setRefundTradeTime(final LocalDateTime refundTradeTime) {
      this.refundTradeTime = refundTradeTime;
   }

   public void setOutTradeNo(final String outTradeNo) {
      this.outTradeNo = outTradeNo;
   }

   public void setAmount(final BigDecimal amount) {
      this.amount = amount;
   }

   public void setPayType(final Integer payType) {
      this.payType = payType;
   }

   public void setPayChannel(final Integer payChannel) {
      this.payChannel = payChannel;
   }

   public void setNuClearMode(final Integer nuClearMode) {
      this.nuClearMode = nuClearMode;
   }

   public void setWalletDetailList(final List<UnifyRefundDTO.WalletDetail> walletDetailList) {
      this.walletDetailList = walletDetailList;
   }

   public void setRefundDetailList(final List<UnifyRefundDTO.Detail> refundDetailList) {
      this.refundDetailList = refundDetailList;
   }

}
