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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.bonus.canteen.core.common.utils.SysUtil;
import com.bonus.canteen.core.order.common.constants.DetailTypeEnum;
import com.bonus.canteen.core.order.common.model.OrderDetail;
import com.bonus.common.houqin.i18n.I18n;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

@ApiModel("订单详情DTO(支付)")
public class OrderDetailPayDTO {
   @ApiModelProperty("明细类别")
   private @NotNull Integer detailType;
   @ApiModelProperty("购物车id")
   private Long shoppingCartId;
   @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("每份重量 g")
   private Integer weightUnit;
   @ApiModelProperty("数量/重量")
   private @NotNull @Min(1L) Integer quantity;
   @ApiModelProperty("总重量 g")
   private Integer totalWeight;
   @ApiModelProperty("商品规格名称")
   private String unitName;
   @ApiModelProperty("销售方式")
   private Integer salesMode;
   @ApiModelProperty("口味名称")
   private String tasteName;
   @ApiModelProperty("存货id")
   private String inventoryId;
   @ApiModelProperty("扩展字段")
   private JsonNode extParam;

   public void setGoodsDishesImgUrl(String goodsDishesImgUrl) {
      this.goodsDishesImgUrl = SysUtil.getCutPath(goodsDishesImgUrl);
   }

   public OrderDetail convertToOrderDetail() {
      OrderDetail orderDetail = OrderDetail.newDefaultDetail(BigDecimal.ZERO, DetailTypeEnum.KEYAMOUNT.getKey());
      BeanUtil.copyProperties(this, orderDetail, CopyOptions.create().setIgnoreNullValue(true));
      if (this.salePrice == null && this.prefPrice == null) {
         orderDetail.setSalePrice(BigDecimal.ZERO);
         orderDetail.setPrefPrice(BigDecimal.ZERO);
      } else if (this.salePrice == null) {
         orderDetail.setSalePrice(this.prefPrice);
         orderDetail.setPrefPrice(this.prefPrice);
      } else if (this.prefPrice == null) {
         orderDetail.setSalePrice(this.salePrice);
         orderDetail.setPrefPrice(this.salePrice);
      }

      return orderDetail;
   }

   public static OrderDetailPayDTO newCustomAmountInstance(BigDecimal amount) {
      OrderDetailPayDTO dto = new OrderDetailPayDTO();
      dto.setGoodsDishesId(0L);
      dto.setGoodsDishesName(I18n.getMessage("order.mac.keystroke-amount", new Object[0]));
      dto.setMenuDetailId(0L);
      dto.setDetailType(DetailTypeEnum.KEYAMOUNT.getKey());
      dto.setSalePrice(amount);
      dto.setPrefPrice(amount);
      return dto;
   }

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

   public Long getShoppingCartId() {
      return this.shoppingCartId;
   }

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

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

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

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

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

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

   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 Integer getSalesMode() {
      return this.salesMode;
   }

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

   public String getInventoryId() {
      return this.inventoryId;
   }

   public JsonNode getExtParam() {
      return this.extParam;
   }

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

   public void setShoppingCartId(final Long shoppingCartId) {
      this.shoppingCartId = shoppingCartId;
   }

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

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

   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 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 setSalesMode(final Integer salesMode) {
      this.salesMode = salesMode;
   }

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

   public void setInventoryId(final String inventoryId) {
      this.inventoryId = inventoryId;
   }

   public void setExtParam(final JsonNode extParam) {
      this.extParam = extParam;
   }

}
