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

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.bonus.canteen.core.common.enums.DeliveryTypeEnum;
import com.bonus.canteen.core.common.page.PageDTO;
import com.bonus.canteen.core.order.common.constants.OrderStateEnum;
import com.bonus.canteen.core.order.common.constants.OrderStateMixEnum;
import com.bonus.canteen.core.order.common.constants.OrderTypeEnum;
import com.bonus.canteen.core.order.common.dto.OrderDeliverySearchParam;
import com.bonus.canteen.core.order.common.query.OrderQueryParam;
import com.bonus.canteen.core.order.utils.LeNumUtil;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.time.LocalDate;
import java.util.List;

@ApiModel("配送明细WebDTO")
public class OrderDeliveryDetailDTO extends PageDTO implements OrderQueryParam {
   private Long orderId;
   @ApiModelProperty("人员姓名/编号/手机号")
   private String custSearchInfo;
   @ApiModelProperty("配送人id")
   private Long deliveryUserId;
   @ApiModelProperty("订餐员id")
   private Long operatorId;
   @ApiModelProperty("餐次类型")
   private List<Integer> mealtimeTypeList;
   @ApiModelProperty("配送状态")
   private List<Integer> deliveryStateList;
   @ApiModelProperty("开始日期")
   private LocalDate startDate;
   @ApiModelProperty("结束日期")
   private LocalDate endDate;
   /** @deprecated */
   private Integer orderType;
   private String mealCode;
   @ApiModelProperty("导出字段")
   private List<String> exportCols;
   @ApiModelProperty("位置idList")
   private List<Long> placeIdList;
   @ApiModelProperty("组织机构")
   private List<Long> orgIdList;
   private List<Integer> orderTypeList;
   private List<Integer> orderStateMixList;
   private List<Long> areaIdList;
   @ApiModelProperty("食堂id范围")
   private List<Long> canteenIdList;
   @ApiModelProperty("档口id范围")
   private List<Long> stallIdList;
   @ApiModelProperty("扩展字段")
   private JsonNode extParam;

   public List<Integer> getOrderTypeList() {
      if (CollUtil.isNotEmpty(this.orderTypeList)) {
         return this.orderTypeList;
      } else {
         return LeNumUtil.isValidId(this.orderType) ? OrderTypeEnum.orderTypeListForWebSearchType(this.orderType) : ListUtil.empty();
      }
   }

   public List<Integer> getOrderStateList() {
      return OrderStateMixEnum.convertToOrderStateList(this.orderStateMixList);
   }

   public List<Integer> getPayStateList() {
      return OrderStateMixEnum.convertToPayStateList(this.orderStateMixList);
   }

   public List<Integer> getOrderRefundStateList() {
      return OrderStateMixEnum.convertToOrderRefundStateList(this.orderStateMixList);
   }

   public OrderDeliverySearchParam convertToOrderSearchParam() {
      OrderDeliverySearchParam param = new OrderDeliverySearchParam();
      param.setDeliveryTypeList(CollUtil.toList(DeliveryTypeEnum.MERCHANT.getKey(), DeliveryTypeEnum.DINING_CABINET.getKey(), DeliveryTypeEnum.FRESH_CABINET.getKey(), DeliveryTypeEnum.TAKE_OUT.getKey(), DeliveryTypeEnum.FOOD_PLACE.getKey()));
      param.setOrderIdList(LeNumUtil.isValidId(this.orderId) ? ListUtil.of(this.orderId) : null);
      param.setCustSearchInfo(this.custSearchInfo);
      param.setOperatorIdList(LeNumUtil.isValidId(this.operatorId) ? ListUtil.of(this.operatorId) : null);
      param.setMealtimeTypeList(this.mealtimeTypeList);
      param.setDishesStateList(this.deliveryStateList);
      param.setStartDate(this.startDate);
      param.setEndDate(this.endDate);
      param.setMealCode(this.mealCode);
      param.setDeliveryRelatedIdList(this.placeIdList);
      param.setOrgIdList(this.orgIdList);
      param.setOrderTypeList(this.orderTypeList);
      param.setAreaIdList(this.areaIdList);
      param.setCanteenIdList(this.canteenIdList);
      param.setStallIdList(this.stallIdList);
      param.setDeliveryUserIdList(LeNumUtil.isValidId(this.deliveryUserId) ? CollUtil.toList(this.deliveryUserId) : null);
      param.setOrderStateList(CollUtil.isNotEmpty(this.getOrderStateList()) ? this.getOrderStateList() : OrderStateEnum.validStateList());
      param.setPayStateList(this.getPayStateList());
      param.setOrderRefundStateList(this.getOrderRefundStateList());
      return param;
   }

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

   public String getCustSearchInfo() {
      return this.custSearchInfo;
   }

   public Long getDeliveryUserId() {
      return this.deliveryUserId;
   }

   public Long getOperatorId() {
      return this.operatorId;
   }

   public List<Integer> getMealtimeTypeList() {
      return this.mealtimeTypeList;
   }

   public List<Integer> getDeliveryStateList() {
      return this.deliveryStateList;
   }

   public LocalDate getStartDate() {
      return this.startDate;
   }

   public LocalDate getEndDate() {
      return this.endDate;
   }

   /** @deprecated */
   @Deprecated
   public Integer getOrderType() {
      return this.orderType;
   }

   public String getMealCode() {
      return this.mealCode;
   }

   public List<String> getExportCols() {
      return this.exportCols;
   }

   public List<Long> getPlaceIdList() {
      return this.placeIdList;
   }

   public List<Long> getOrgIdList() {
      return this.orgIdList;
   }

   public List<Integer> getOrderStateMixList() {
      return this.orderStateMixList;
   }

   public List<Long> getAreaIdList() {
      return this.areaIdList;
   }

   public List<Long> getCanteenIdList() {
      return this.canteenIdList;
   }

   public List<Long> getStallIdList() {
      return this.stallIdList;
   }

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

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

   public void setCustSearchInfo(final String custSearchInfo) {
      this.custSearchInfo = custSearchInfo;
   }

   public void setDeliveryUserId(final Long deliveryUserId) {
      this.deliveryUserId = deliveryUserId;
   }

   public void setOperatorId(final Long operatorId) {
      this.operatorId = operatorId;
   }

   public void setMealtimeTypeList(final List<Integer> mealtimeTypeList) {
      this.mealtimeTypeList = mealtimeTypeList;
   }

   public void setDeliveryStateList(final List<Integer> deliveryStateList) {
      this.deliveryStateList = deliveryStateList;
   }

   public void setStartDate(final LocalDate startDate) {
      this.startDate = startDate;
   }

   public void setEndDate(final LocalDate endDate) {
      this.endDate = endDate;
   }

   /** @deprecated */
   @Deprecated
   public void setOrderType(final Integer orderType) {
      this.orderType = orderType;
   }

   public void setMealCode(final String mealCode) {
      this.mealCode = mealCode;
   }

   public void setExportCols(final List<String> exportCols) {
      this.exportCols = exportCols;
   }

   public void setPlaceIdList(final List<Long> placeIdList) {
      this.placeIdList = placeIdList;
   }

   public void setOrgIdList(final List<Long> orgIdList) {
      this.orgIdList = orgIdList;
   }

   public void setOrderTypeList(final List<Integer> orderTypeList) {
      this.orderTypeList = orderTypeList;
   }

   public void setOrderStateMixList(final List<Integer> orderStateMixList) {
      this.orderStateMixList = orderStateMixList;
   }

   public void setAreaIdList(final List<Long> areaIdList) {
      this.areaIdList = areaIdList;
   }

   public void setCanteenIdList(final List<Long> canteenIdList) {
      this.canteenIdList = canteenIdList;
   }

   public void setStallIdList(final List<Long> stallIdList) {
      this.stallIdList = stallIdList;
   }

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

}
