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

import cn.hutool.core.util.NumberUtil;
import com.bonus.canteen.core.menu.constant.MenuSalesTypeEnum;
import com.bonus.canteen.core.order.common.model.OrderDetail;
import com.bonus.canteen.core.order.common.model.OrderRefundDetail;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;

public class NoticePrintDetailVO {
   private Long goodsDishesId;
   private String goodsDishesName;
   @ApiModelProperty("规格")
   private String specName;
   @ApiModelProperty("销售方式(1按份,2称重)")
   private Integer salesMode;
   @ApiModelProperty("数量/重量")
   private Integer quantity;
   @ApiModelProperty("每份重量 g")
   private Integer weightUnit;
   @ApiModelProperty("商品单价 单位为分")
   private BigDecimal price;
   @ApiModelProperty("小计金额 单位为分")
   private BigDecimal realAmount;
   @ApiModelProperty("营养信息")
   private NoticePrintNutritionVO nutritionVO;

   public double totalGram() {
      return MenuSalesTypeEnum.WEIGHT_ON.key().equals(this.salesMode) ? (double)(this.quantity != null ? this.quantity : 0) : (double)NumberUtil.mul(this.quantity, this.weightUnit).intValue();
   }

   public NoticePrintNutritionVO getNutritionVO() {
      return this.nutritionVO;
   }

   public static NoticePrintDetailVO byOrderDetail(OrderDetail orderDetail) {
      NoticePrintDetailVO printDetail = new NoticePrintDetailVO();
      printDetail.setGoodsDishesId(orderDetail.getGoodsDishesId());
      printDetail.setGoodsDishesName(orderDetail.getGoodsDishesName());
      printDetail.setPrice(orderDetail.getPrice());
      printDetail.setSpecName(orderDetail.getTasteName());
      printDetail.setSalesMode(orderDetail.getSalesMode());
      printDetail.setQuantity(orderDetail.getQuantity() - orderDetail.getGoodsRefundNum());
      printDetail.setRealAmount(orderDetail.getRealAmount().subtract(orderDetail.getRefundAmount()));
      printDetail.setWeightUnit(orderDetail.getWeightUnit());
      return printDetail;
   }

   public static NoticePrintDetailVO byRefund(OrderDetail orderDetail, OrderRefundDetail orderRefundDetail) {
      NoticePrintDetailVO printDetail = new NoticePrintDetailVO();
      printDetail.setGoodsDishesId(orderDetail.getGoodsDishesId());
      printDetail.setGoodsDishesName(orderDetail.getGoodsDishesName());
      printDetail.setPrice(orderDetail.getPrice());
      printDetail.setSpecName(orderDetail.getTasteName());
      printDetail.setSalesMode(orderDetail.getSalesMode());
      printDetail.setQuantity(orderRefundDetail.getRealQuantity());
      printDetail.setRealAmount(orderRefundDetail.getRealRefundAmount());
      printDetail.setWeightUnit(orderDetail.getWeightUnit());
      return printDetail;
   }

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

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

   public String getSpecName() {
      return this.specName;
   }

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

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

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

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

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

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

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

   public void setSpecName(final String specName) {
      this.specName = specName;
   }

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

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

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

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

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

   public void setNutritionVO(final NoticePrintNutritionVO nutritionVO) {
      this.nutritionVO = nutritionVO;
   }

}
