package com.bonus.canteen.core.order.weight.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.menu.constant.MenuSalesTypeEnum;
import com.bonus.canteen.core.order.common.model.OrderDetail;
import com.bonus.canteen.core.order.weight.dto.OrderWeightPlaceDetailDTO;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.format.annotation.DateTimeFormat;

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

public class OrderWeightDetailVO {
   @ApiModelProperty("详情id")
   private Long detailId;
   @ApiModelProperty("订单id")
   private Long orderId;
   private String submitKey;
   @ApiModelProperty("商品菜品id")
   private Long goodsDishesId;
   @ApiModelProperty("商品菜品名称")
   private String goodsDishesName;
   @ApiModelProperty("商品菜品图片路径")
   private String goodsDishesImgUrl;
   @ApiModelProperty("菜品详情id")
   private Long menuDetailId;
   @ApiModelProperty("售卖价格 分")
   private BigDecimal salePrice;
   @ApiModelProperty("优惠价格 分")
   private BigDecimal prefPrice;
   @ApiModelProperty("计算价格 分")
   private BigDecimal price;
   @ApiModelProperty("每份重量 g")
   private Integer weightUnit;
   @ApiModelProperty("数量/重量")
   private Integer quantity;
   @ApiModelProperty("总重量 g")
   private Integer totalWeight;
   @ApiModelProperty("商品规格名称")
   private String unitName;
   @ApiModelProperty("订单详情原价总金额 分")
   private BigDecimal totalAmount;
   @ApiModelProperty("订单详情实际价总金额 分")
   private BigDecimal calcTotalAmount;
   @ApiModelProperty("实际付款金额 分")
   private BigDecimal realAmount;
   @ApiModelProperty("已退款金额")
   private BigDecimal refundAmount;
   @ApiModelProperty("销售方式 1 按份 2 称重")
   private Integer salesMode;
   @ApiModelProperty("口味名称")
   private String tasteName;
   @ApiModelProperty("订单详情状态 1 正常 2 已退菜 3 部分退菜")
   private Integer detailState;
   @ApiModelProperty("商品已退数量")
   private Integer goodsRefundNum;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   private LocalDateTime crtime;
   private Integer customDishesId;
   private String machineSn;
   private String machineNum;

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

   @DateTimeFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   public LocalDateTime getSubmitTime() {
      return this.crtime;
   }

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

   public static OrderWeightDetailVO of(OrderDetail orderDetail, OrderWeightPlaceDetailDTO orderWeightPlaceDetailDTO) {
      OrderWeightDetailVO vo = (OrderWeightDetailVO)BeanUtil.copyProperties(orderDetail, OrderWeightDetailVO.class, new String[0]);
      if (orderWeightPlaceDetailDTO != null) {
         vo.setCustomDishesId(orderWeightPlaceDetailDTO.getCustomDishesId());
         vo.setMachineNum(orderWeightPlaceDetailDTO.getMachineNum());
      }

      return vo;
   }

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

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

   public String getSubmitKey() {
      return this.submitKey;
   }

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

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

   public Long getMenuDetailId() {
      return this.menuDetailId;
   }

   public BigDecimal getSalePrice() {
      return this.salePrice;
   }

   public BigDecimal getPrefPrice() {
      return this.prefPrice;
   }

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

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

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

   public Integer getTotalWeight() {
      return this.totalWeight;
   }

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

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

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

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

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

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

   public String getTasteName() {
      return this.tasteName;
   }

   public Integer getDetailState() {
      return this.detailState;
   }

   public Integer getGoodsRefundNum() {
      return this.goodsRefundNum;
   }

   public LocalDateTime getCrtime() {
      return this.crtime;
   }

   public Integer getCustomDishesId() {
      return this.customDishesId;
   }

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

   public String getMachineNum() {
      return this.machineNum;
   }

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

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

   public void setSubmitKey(final String submitKey) {
      this.submitKey = submitKey;
   }

   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 setMenuDetailId(final Long menuDetailId) {
      this.menuDetailId = menuDetailId;
   }

   public void setSalePrice(final BigDecimal salePrice) {
      this.salePrice = salePrice;
   }

   public void setPrefPrice(final BigDecimal prefPrice) {
      this.prefPrice = prefPrice;
   }

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

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

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

   public void setTotalWeight(final Integer totalWeight) {
      this.totalWeight = totalWeight;
   }

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

   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 setRefundAmount(final BigDecimal refundAmount) {
      this.refundAmount = refundAmount;
   }

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

   public void setTasteName(final String tasteName) {
      this.tasteName = tasteName;
   }

   public void setDetailState(final Integer detailState) {
      this.detailState = detailState;
   }

   public void setGoodsRefundNum(final Integer goodsRefundNum) {
      this.goodsRefundNum = goodsRefundNum;
   }

   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   public void setCrtime(final LocalDateTime crtime) {
      this.crtime = crtime;
   }

   public void setCustomDishesId(final Integer customDishesId) {
      this.customDishesId = customDishesId;
   }

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

   public void setMachineNum(final String machineNum) {
      this.machineNum = machineNum;
   }

}
