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

import cn.hutool.core.bean.BeanUtil;
import com.bonus.canteen.core.common.enums.DeliveryTypeEnum;
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 com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.format.annotation.DateTimeFormat;

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

@ApiModel("设备订单支付DTO")
public class OrderPayAndroidDTO {
   @ApiModelProperty("托盘物理号")
   private String plateSerialNum;
   @ApiModelProperty("配送费 分")
   private BigDecimal deliveryAmount;
   @ApiModelProperty("包装费 分")
   private BigDecimal packingAmount;
   @ApiModelProperty("食堂/超市/班车线路 id")
   private @NotNull(
   message = "{order.param-illegal}"
) Long canteenId;
   @ApiModelProperty("食堂/超市/班车线路 名称")
   private String canteenName;
   @ApiModelProperty("档口id")
   private Long stallId;
   @ApiModelProperty("档口名称")
   private String stallName;
   @ApiModelProperty("餐次类型")
   private Integer mealtimeType;
   @ApiModelProperty("餐次名称")
   private String mealtimeName;
   @ApiModelProperty("配送关联id（位置/取餐柜id）")
   private Long deliveryRelatedId;
   @ApiModelProperty("收货人姓名")
   private String consigneeName;
   @ApiModelProperty("收货人手机号")
   private String consigneeMobile;
   @ApiModelProperty("收货人地址")
   private String consigneeAddress;
   @ApiModelProperty("配送方式")
   private Integer deliveryType;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   private LocalDateTime deliveryTime;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd"
   )
   @ApiModelProperty("订单日期 yyyy-MM-dd")
   private LocalDate orderDate;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @ApiModelProperty("下单时间 yyyy-MM-dd HH:mm:ss")
   private @NotNull(
   message = "{order.param-illegal}"
) LocalDateTime orderTime;
   @ApiModelProperty("订单备注")
   private String remark;
   @ApiModelProperty("扩展字段")
   private JsonNode extParam;
   @ApiModelProperty("订单明细列表")
   private @NotNull(
   message = "订单明细不可为空"
) @Size(
   min = 1,
   max = 50,
   message = "订单明细最少1笔最多50笔"
) List<@Valid OrderDetailPayDTO> orderDetailList;

   public OrderInfo convertToOrderInfo() {
      OrderInfo orderInfo = OrderInfo.newDefaultInstance();
      BeanUtil.copyProperties(this, orderInfo, new String[0]);
      orderInfo.setDeliveryAmount(this.deliveryAmount != null ? this.deliveryAmount : BigDecimal.ZERO);
      orderInfo.setPackingAmount(this.packingAmount != null ? this.packingAmount : BigDecimal.ZERO);
      if (orderInfo.getOrderDate() == null) {
         orderInfo.setOrderDate(this.orderTime.toLocalDate());
      }

      return orderInfo;
   }

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

   public OrderPayAndroidDTO() {
      this.deliveryType = DeliveryTypeEnum.NONE.getKey();
   }

   public String getPlateSerialNum() {
      return this.plateSerialNum;
   }

   public BigDecimal getDeliveryAmount() {
      return this.deliveryAmount;
   }

   public BigDecimal getPackingAmount() {
      return this.packingAmount;
   }

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

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

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

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

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

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

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

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

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

   public String getConsigneeAddress() {
      return this.consigneeAddress;
   }

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

   public LocalDateTime getDeliveryTime() {
      return this.deliveryTime;
   }

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

   public LocalDateTime getOrderTime() {
      return this.orderTime;
   }

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

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

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

   public OrderPayAndroidDTO setPlateSerialNum(final String plateSerialNum) {
      this.plateSerialNum = plateSerialNum;
      return this;
   }

   public OrderPayAndroidDTO setDeliveryAmount(final BigDecimal deliveryAmount) {
      this.deliveryAmount = deliveryAmount;
      return this;
   }

   public OrderPayAndroidDTO setPackingAmount(final BigDecimal packingAmount) {
      this.packingAmount = packingAmount;
      return this;
   }

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

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

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

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

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

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

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

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

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

   public OrderPayAndroidDTO setConsigneeAddress(final String consigneeAddress) {
      this.consigneeAddress = consigneeAddress;
      return this;
   }

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

   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   public OrderPayAndroidDTO setDeliveryTime(final LocalDateTime deliveryTime) {
      this.deliveryTime = deliveryTime;
      return this;
   }

   @JsonFormat(
      pattern = "yyyy-MM-dd"
   )
   public OrderPayAndroidDTO setOrderDate(final LocalDate orderDate) {
      this.orderDate = orderDate;
      return this;
   }

   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   public OrderPayAndroidDTO setOrderTime(final LocalDateTime orderTime) {
      this.orderTime = orderTime;
      return this;
   }

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

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

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

}
