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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.canteen.core.order.common.constants.OrderTypeEnum;
import com.bonus.canteen.core.order.common.dto.OrderDetailPayDTO;
import com.bonus.canteen.core.order.common.model.OrderDelivery;
import com.bonus.canteen.core.order.common.model.OrderInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.Valid;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@ApiModel("预订餐下单DTO")
public class OrderReserveMealDTO implements OrderMobileParam {
   @ApiModelProperty("食堂id")
   private Long canteenId;
   @ApiModelProperty("档口或店铺id")
   private Long stallId;
   @ApiModelProperty(
      value = "餐次类型",
      required = true
   )
   private Integer mealtimeType;
   @ApiModelProperty("订单日期 yyyy-MM-dd")
   private LocalDate orderDate;
   @ApiModelProperty("取餐柜id")
   private Long counterId;
   @ApiModelProperty("配送费 单位为分")
   private @DecimalMin(
   value = "0",
   message = "配送费不能小于0"
) BigDecimal deliveryFee;
   @ApiModelProperty("配送方式")
   private Integer deliveryType;
   @ApiModelProperty("位置id/取餐柜id")
   private Long deliveryRelatedId;
   @ApiModelProperty("收货人姓名")
   private String consigneeName;
   @ApiModelProperty("收货人手机号")
   private String consigneeMobile;
   @ApiModelProperty("配送地址")
   private String deliveryAddr;
   @ApiModelProperty("订单备注")
   private String remark;
   @ApiModelProperty(
      value = "订单明细",
      required = true
   )
   private @NotNull(
   message = "菜品明细不可为空"
) @Size(
   min = 1,
   max = 50,
   message = "订单明细最少1笔最多50笔"
) List<@Valid OrderDetailPayDTO> orderDetailList;
   @ApiModelProperty("食堂名称")
   private String canteenName;
   @ApiModelProperty("档口名称")
   private String stallName;
   @ApiModelProperty("餐次名称")
   private String mealtimeName;

   public OrderInfo convertToOrderInfo() {
      OrderInfo orderInfo = OrderInfo.newDefaultInstance();
      BeanUtil.copyProperties(this, orderInfo, new String[0]);
      orderInfo.setOrderType(OrderTypeEnum.RESERVE_MEAL.getKey());
      orderInfo.setIfQuickFail(LeConstants.COMMON_NO);
      return orderInfo;
   }

   public OrderDelivery convertToOrderDelivery() {
      OrderDelivery orderDelivery = OrderDelivery.newDefaultInstance();
      BeanUtil.copyProperties(this, orderDelivery, new String[0]);
      orderDelivery.setDeliveryRelatedId(this.counterId);
      orderDelivery.setConsigneeAddress(this.deliveryAddr);
      return orderDelivery;
   }

   public List<OrderDetailPayDTO> convertToOrderDetailList() {
      return CollUtil.isNotEmpty(this.orderDetailList) ? this.orderDetailList : ListUtil.empty();
   }

   public Long getCanteenId() {
      return this.canteenId;
   }

   public Long getStallId() {
      return this.stallId;
   }

   public Integer getMealtimeType() {
      return this.mealtimeType;
   }

   public LocalDate getOrderDate() {
      return this.orderDate;
   }

   public Long getCounterId() {
      return this.counterId;
   }

   public BigDecimal getDeliveryFee() {
      return this.deliveryFee;
   }

   public Integer getDeliveryType() {
      return this.deliveryType;
   }

   public Long getDeliveryRelatedId() {
      return this.deliveryRelatedId;
   }

   public String getConsigneeName() {
      return this.consigneeName;
   }

   public String getConsigneeMobile() {
      return this.consigneeMobile;
   }

   public String getDeliveryAddr() {
      return this.deliveryAddr;
   }

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

   public List<@Valid OrderDetailPayDTO> getOrderDetailList() {
      return this.orderDetailList;
   }

   public String getCanteenName() {
      return this.canteenName;
   }

   public String getStallName() {
      return this.stallName;
   }

   public String getMealtimeName() {
      return this.mealtimeName;
   }

   public void setCanteenId(final Long canteenId) {
      this.canteenId = canteenId;
   }

   public void setStallId(final Long stallId) {
      this.stallId = stallId;
   }

   public void setMealtimeType(final Integer mealtimeType) {
      this.mealtimeType = mealtimeType;
   }

   public void setOrderDate(final LocalDate orderDate) {
      this.orderDate = orderDate;
   }

   public void setCounterId(final Long counterId) {
      this.counterId = counterId;
   }

   public void setDeliveryFee(final BigDecimal deliveryFee) {
      this.deliveryFee = deliveryFee;
   }

   public void setDeliveryType(final Integer deliveryType) {
      this.deliveryType = deliveryType;
   }

   public void setDeliveryRelatedId(final Long deliveryRelatedId) {
      this.deliveryRelatedId = deliveryRelatedId;
   }

   public void setConsigneeName(final String consigneeName) {
      this.consigneeName = consigneeName;
   }

   public void setConsigneeMobile(final String consigneeMobile) {
      this.consigneeMobile = consigneeMobile;
   }

   public void setDeliveryAddr(final String deliveryAddr) {
      this.deliveryAddr = deliveryAddr;
   }

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

   public void setOrderDetailList(final List<@Valid OrderDetailPayDTO> orderDetailList) {
      this.orderDetailList = orderDetailList;
   }

   public void setCanteenName(final String canteenName) {
      this.canteenName = canteenName;
   }

   public void setStallName(final String stallName) {
      this.stallName = stallName;
   }

   public void setMealtimeName(final String mealtimeName) {
      this.mealtimeName = mealtimeName;
   }

}
