package com.bonus.canteen.core.order.common.vo;

import com.bonus.canteen.core.common.constant.LeRetCodeEnum;
import com.bonus.canteen.core.order.common.model.OrderInfo;
import com.bonus.canteen.core.order.common.model.OrderRefund;
import com.bonus.canteen.core.pay.api.vo.UnifyRefundVO;
import com.bonus.canteen.core.pay.common.constants.PayStateEnum;

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

public class OrderRefundResultVO {
   private Integer resultCode;
   private String resultMsg;
   private Long orderId;
   private String macOrderId;
   private Long orderRefundId;
   private String macRefundId;
   private BigDecimal orderRealAmount;
   private BigDecimal orderRefundAmount;
   private BigDecimal refundAmount;
   private BigDecimal refundFeeAmount;
   private BigDecimal realRefundAmount;
   private LocalDateTime refundTime;
   private String remark;
   private String notAllowedCancelHour;
   private String feeTimeOfDayBefore;
   private String feeRate;

   public static OrderRefundResultVO of(OrderInfo orderInfo, OrderRefund orderRefund, OrderRefundFeeConfigVO feeVO) {
      OrderRefundResultVO vo = new OrderRefundResultVO();
      vo.setResultCode(LeRetCodeEnum.SUCC.getKey());
      vo.setResultMsg(LeRetCodeEnum.SUCC.getDesc());
      vo.setOrderId(orderRefund.getOrderId());
      vo.setMacOrderId(orderRefund.getMacOrderId());
      vo.setOrderRefundId(orderRefund.getOrderRefundId());
      vo.setMacRefundId(orderRefund.getMacRefundId());
      vo.setOrderRealAmount(orderInfo.getRealAmount());
      vo.setOrderRefundAmount(orderInfo.getRefundAmount());
      vo.setRefundAmount(orderRefund.getRefundAmount());
      vo.setRealRefundAmount(orderRefund.getRealRefundAmount());
      vo.setRefundFeeAmount(orderRefund.getFeeAmount());
      vo.setRefundTime(orderRefund.getApplyTime());
      vo.setRemark(orderRefund.getApplyReason());
      if (feeVO != null) {
         vo.fillFeeConfigVO(feeVO);
      }

      return vo;
   }

   public static OrderRefundResultVO of(OrderInfo orderInfo, OrderRefund orderRefund, OrderRefundFeeConfigVO feeVO,
                                        UnifyRefundVO refundVO) {
      OrderRefundResultVO vo = of(orderInfo, orderRefund, feeVO);
      if (PayStateEnum.isPaidState(refundVO.getCode())) {
         vo.setResultCode(LeRetCodeEnum.SUCC.getKey());
         vo.setResultMsg(LeRetCodeEnum.SUCC.getDesc());
      } else {
         vo.setResultCode(LeRetCodeEnum.FAIL.getKey());
         vo.setResultMsg(refundVO.getMsg());
      }

      return vo;
   }

   public boolean ifSuccess() {
      return LeRetCodeEnum.SUCC.getKey().equals(this.resultCode);
   }

   public void fillFeeConfigVO(OrderRefundFeeConfigVO feeVO) {
      this.notAllowedCancelHour = feeVO.getNotAllowedCancelHour();
      this.feeTimeOfDayBefore = feeVO.getFeeTimeOfDayBefore();
      this.feeRate = feeVO.getFeeRate();
   }

   public Integer getResultCode() {
      return this.resultCode;
   }

   public String getResultMsg() {
      return this.resultMsg;
   }

   public Long getOrderId() {
      return this.orderId;
   }

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

   public Long getOrderRefundId() {
      return this.orderRefundId;
   }

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

   public BigDecimal getOrderRealAmount() {
      return this.orderRealAmount;
   }

   public BigDecimal getOrderRefundAmount() {
      return this.orderRefundAmount;
   }

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

   public BigDecimal getRefundFeeAmount() {
      return this.refundFeeAmount;
   }

   public BigDecimal getRealRefundAmount() {
      return this.realRefundAmount;
   }

   public LocalDateTime getRefundTime() {
      return this.refundTime;
   }

   public String getRemark() {
      return this.remark;
   }

   public String getNotAllowedCancelHour() {
      return this.notAllowedCancelHour;
   }

   public String getFeeTimeOfDayBefore() {
      return this.feeTimeOfDayBefore;
   }

   public String getFeeRate() {
      return this.feeRate;
   }

   public void setResultCode(final Integer resultCode) {
      this.resultCode = resultCode;
   }

   public void setResultMsg(final String resultMsg) {
      this.resultMsg = resultMsg;
   }

   public void setOrderId(final Long orderId) {
      this.orderId = orderId;
   }

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

   public void setOrderRefundId(final Long orderRefundId) {
      this.orderRefundId = orderRefundId;
   }

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

   public void setOrderRealAmount(final BigDecimal orderRealAmount) {
      this.orderRealAmount = orderRealAmount;
   }

   public void setOrderRefundAmount(final BigDecimal orderRefundAmount) {
      this.orderRefundAmount = orderRefundAmount;
   }

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

   public void setRefundFeeAmount(final BigDecimal refundFeeAmount) {
      this.refundFeeAmount = refundFeeAmount;
   }

   public void setRealRefundAmount(final BigDecimal realRefundAmount) {
      this.realRefundAmount = realRefundAmount;
   }

   public void setRefundTime(final LocalDateTime refundTime) {
      this.refundTime = refundTime;
   }

   public void setRemark(final String remark) {
      this.remark = remark;
   }

   public void setNotAllowedCancelHour(final String notAllowedCancelHour) {
      this.notAllowedCancelHour = notAllowedCancelHour;
   }

   public void setFeeTimeOfDayBefore(final String feeTimeOfDayBefore) {
      this.feeTimeOfDayBefore = feeTimeOfDayBefore;
   }

   public void setFeeRate(final String feeRate) {
      this.feeRate = feeRate;
   }

}
