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

import cn.hutool.core.collection.CollUtil;
import com.bonus.core.common.utils.JacksonUtil;
import com.bonus.core.order.common.model.OrderDetail;
import com.bonus.core.order.common.model.OrderRefundDetail;
import com.bonus.core.pay.common.model.TradeRecord;

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

public class UnifyRefundDTO {
   private Long tradeId;
   private Long orderRechargeId;
   private Long refundTradeId;
   private Long refundId;
   private String macRefundId;
   private BigDecimal refundAmount;
   private List<Detail> detailList = CollUtil.newArrayList(new Detail[0]);
   private List<ChannelDetail> channelAssignList = CollUtil.newArrayList(new ChannelDetail[0]);

   public static UnifyRefundDTO ofNullable(TradeRecord refundTradeRecord) {
      return refundTradeRecord.getParam() != null ? (UnifyRefundDTO) JacksonUtil.treeToValue(refundTradeRecord.getParam(), UnifyRefundDTO.class) : null;
   }

   public Long getTradeId() {
      return this.tradeId;
   }

   public Long getOrderRechargeId() {
      return this.orderRechargeId;
   }

   public Long getRefundTradeId() {
      return this.refundTradeId;
   }

   public Long getRefundId() {
      return this.refundId;
   }

   public String getMacRefundId() {
      return this.macRefundId;
   }

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

   public List<Detail> getDetailList() {
      return this.detailList;
   }

   public List<ChannelDetail> getChannelAssignList() {
      return this.channelAssignList;
   }

   public void setTradeId(final Long tradeId) {
      this.tradeId = tradeId;
   }

   public void setOrderRechargeId(final Long orderRechargeId) {
      this.orderRechargeId = orderRechargeId;
   }

   public void setRefundTradeId(final Long refundTradeId) {
      this.refundTradeId = refundTradeId;
   }

   public void setRefundId(final Long refundId) {
      this.refundId = refundId;
   }

   public void setMacRefundId(final String macRefundId) {
      this.macRefundId = macRefundId;
   }

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

   public void setDetailList(final List<Detail> detailList) {
      this.detailList = detailList;
   }

   public void setChannelAssignList(final List<ChannelDetail> channelAssignList) {
      this.channelAssignList = channelAssignList;
   }


   public static class Detail {
      private Long detailId;
      private Long goodsDishesId;
      private String goodsDishesName;
      private Integer refundQuantity;
      private BigDecimal refundAmount;

      public static Detail of(OrderRefundDetail refundDetail, OrderDetail orderDetail) {
         Detail detail = new Detail();
         detail.setDetailId(refundDetail.getDetailId());
         detail.setRefundQuantity(refundDetail.getRealQuantity());
         detail.setRefundAmount(refundDetail.getRefundAmount());
         if (orderDetail != null) {
            detail.setGoodsDishesId(orderDetail.getGoodsDishesId());
            detail.setGoodsDishesName(orderDetail.getGoodsDishesName());
         }

         return detail;
      }

      public Long getDetailId() {
         return this.detailId;
      }

      public Long getGoodsDishesId() {
         return this.goodsDishesId;
      }

      public String getGoodsDishesName() {
         return this.goodsDishesName;
      }

      public Integer getRefundQuantity() {
         return this.refundQuantity;
      }

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

      public void setDetailId(final Long detailId) {
         this.detailId = detailId;
      }

      public void setGoodsDishesId(final Long goodsDishesId) {
         this.goodsDishesId = goodsDishesId;
      }

      public void setGoodsDishesName(final String goodsDishesName) {
         this.goodsDishesName = goodsDishesName;
      }

      public void setRefundQuantity(final Integer refundQuantity) {
         this.refundQuantity = refundQuantity;
      }

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

   }

   public static class ChannelDetail {
      private Long tradeChannelId;
      private BigDecimal refundAmount;
      private List<WalletDetail> walletDetailList;

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

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

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

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

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

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

   }

   public static class WalletDetail {
      private Integer walletId;
      private BigDecimal refundAmount;

      public Integer getWalletId() {
         return this.walletId;
      }

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

      public void setWalletId(final Integer walletId) {
         this.walletId = walletId;
      }

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

   }
}
