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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.NumberUtil;
import com.bonus.canteen.core.common.utils.SysUtil;
import com.bonus.canteen.core.order.common.model.OrderDetail;
import com.bonus.canteen.core.order.common.model.OrderRefundDetail;
import com.bonus.canteen.core.order.common.vo.OrderDetailWithImage;

import java.math.BigDecimal;

public class OrderRefundDetailVO implements OrderDetailWithImage {
   private Integer detailType;
   private Long orderRefundId;
   private Long detailId;
   private Long goodsDishesId;
   private String goodsDishesName;
   private String goodsDishesImgUrl;
   private BigDecimal price;
   private BigDecimal realPrice;
   private Integer salesMode;
   private Integer weightUnit;
   private String unitName;
   private Integer detailQuantity;
   private Integer detailRefundQuantity;
   private BigDecimal totalAmount;
   private BigDecimal calcTotalAmount;
   private BigDecimal realAmount;
   private Integer quantity;
   private Integer realQuantity;
   private BigDecimal refundAmount;
   private BigDecimal realRefundAmount;
   private Integer restoreQuantity;

   public BigDecimal getRealPrice() {
      return this.detailQuantity != null && this.detailQuantity != 0 ? NumberUtil.div(this.realAmount, this.detailQuantity, 2) : this.realAmount;
   }

   public String getGoodsDishesImgUrl() {
      return SysUtil.getCutFileUrl(this.goodsDishesImgUrl);
   }

   public void fillOrderDetail(OrderDetail orderDetail) {
      if (orderDetail != null) {
         this.detailType = orderDetail.getDetailType();
         this.goodsDishesId = orderDetail.getGoodsDishesId();
         this.goodsDishesName = orderDetail.getGoodsDishesName();
         this.goodsDishesImgUrl = orderDetail.getGoodsDishesImgUrl();
         this.price = orderDetail.getPrice();
         this.salesMode = orderDetail.getSalesMode();
         this.weightUnit = orderDetail.getWeightUnit();
         this.unitName = orderDetail.getUnitName();
         this.detailQuantity = orderDetail.getQuantity();
         this.detailRefundQuantity = orderDetail.getGoodsRefundNum();
         this.totalAmount = orderDetail.getTotalAmount();
         this.calcTotalAmount = orderDetail.getCalcTotalAmount();
         this.realAmount = orderDetail.getRealAmount();
      }
   }

   public static OrderRefundDetailVO of(OrderRefundDetail orderRefundDetail, OrderDetail orderDetail) {
      OrderRefundDetailVO vo = (OrderRefundDetailVO)BeanUtil.copyProperties(orderRefundDetail, OrderRefundDetailVO.class, new String[0]);
      vo.fillOrderDetail(orderDetail);
      return vo;
   }

   public Integer getDetailType() {
      return this.detailType;
   }

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

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

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

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

   public BigDecimal getPrice() {
      return this.price;
   }

   public Integer getSalesMode() {
      return this.salesMode;
   }

   public Integer getWeightUnit() {
      return this.weightUnit;
   }

   public String getUnitName() {
      return this.unitName;
   }

   public Integer getDetailQuantity() {
      return this.detailQuantity;
   }

   public Integer getDetailRefundQuantity() {
      return this.detailRefundQuantity;
   }

   public BigDecimal getTotalAmount() {
      return this.totalAmount;
   }

   public BigDecimal getCalcTotalAmount() {
      return this.calcTotalAmount;
   }

   public BigDecimal getRealAmount() {
      return this.realAmount;
   }

   public Integer getQuantity() {
      return this.quantity;
   }

   public Integer getRealQuantity() {
      return this.realQuantity;
   }

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

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

   public Integer getRestoreQuantity() {
      return this.restoreQuantity;
   }

   public void setDetailType(final Integer detailType) {
      this.detailType = detailType;
   }

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

   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 setGoodsDishesImgUrl(final String goodsDishesImgUrl) {
      this.goodsDishesImgUrl = goodsDishesImgUrl;
   }

   public void setPrice(final BigDecimal price) {
      this.price = price;
   }

   public void setRealPrice(final BigDecimal realPrice) {
      this.realPrice = realPrice;
   }

   public void setSalesMode(final Integer salesMode) {
      this.salesMode = salesMode;
   }

   public void setWeightUnit(final Integer weightUnit) {
      this.weightUnit = weightUnit;
   }

   public void setUnitName(final String unitName) {
      this.unitName = unitName;
   }

   public void setDetailQuantity(final Integer detailQuantity) {
      this.detailQuantity = detailQuantity;
   }

   public void setDetailRefundQuantity(final Integer detailRefundQuantity) {
      this.detailRefundQuantity = detailRefundQuantity;
   }

   public void setTotalAmount(final BigDecimal totalAmount) {
      this.totalAmount = totalAmount;
   }

   public void setCalcTotalAmount(final BigDecimal calcTotalAmount) {
      this.calcTotalAmount = calcTotalAmount;
   }

   public void setRealAmount(final BigDecimal realAmount) {
      this.realAmount = realAmount;
   }

   public void setQuantity(final Integer quantity) {
      this.quantity = quantity;
   }

   public void setRealQuantity(final Integer realQuantity) {
      this.realQuantity = realQuantity;
   }

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

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

   public void setRestoreQuantity(final Integer restoreQuantity) {
      this.restoreQuantity = restoreQuantity;
   }

}
