package com.bonus.canteen.core.order.deprecated.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.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.bonus.common.houqin.constant.LeConstants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

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

@ApiModel("订单查询菜品领取DTO")
public class OrderDetailSumGetDTO extends PageDTO implements OrderQueryParam {
   @ApiModelProperty("餐次id")
   private Long intervalId;
   @ApiModelProperty("餐次id")
   private List<Integer> mealtimeTypeList;
   @ApiModelProperty("位置idList")
   private List<Long> placeIdList;
   @ApiModelProperty("就餐开始日期 yyyy-MM-dd")
   private LocalDate ordGoodsDateStart;
   @ApiModelProperty("就餐结束日期 yyyy-MM-dd")
   private LocalDate ordGoodsDateEnd;
   @ApiModelProperty("导出字段")
   private List<String> exportCols;
   @ApiModelProperty("订餐员")
   private Long reserveUserId;
   @ApiModelProperty("食堂id")
   private Long canteenId;
   @ApiModelProperty("档口id")
   private Long shopstallId;
   /** @deprecated */
   private Integer orderType;
   private List<Integer> orderTypeList;
   private List<Long> areaIdList;
   private List<Long> canteenIdList;
   private List<Long> stallIdList;

   public List<Integer> getMealtimeTypeList() {
      if (CollUtil.isNotEmpty(this.mealtimeTypeList)) {
         return this.mealtimeTypeList;
      } else {
         return (List)(LeNumUtil.isValidId(this.intervalId) ? ListUtil.toList(new Integer[]{this.intervalId.intValue()}) : ListUtil.empty());
      }
   }

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

   public void setStartDate(LocalDate orderDate) {
      this.ordGoodsDateStart = orderDate;
   }

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

   public void setEndDate(LocalDate orderDate) {
      this.ordGoodsDateEnd = orderDate;
   }

   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 OrderDeliverySearchParam convertToOrderDeliverySearchParam(List<Long> userPlaceIdList) {
      OrderDeliverySearchParam param = new OrderDeliverySearchParam();
      param.setIfExistsPlaceId(LeConstants.COMMON_YES);
      param.setOrderStateList(OrderStateEnum.validStateList());
      param.setDeliveryTypeList(CollUtil.toList(new Integer[]{DeliveryTypeEnum.MERCHANT.getKey(), DeliveryTypeEnum.DINING_CABINET.getKey(), DeliveryTypeEnum.FRESH_CABINET.getKey(), DeliveryTypeEnum.TAKE_OUT.getKey(), DeliveryTypeEnum.FOOD_PLACE.getKey()}));
      param.setAreaIdList(this.areaIdList);
      param.setCanteenIdList(this.canteenIdList);
      param.setStallIdList(this.stallIdList);
      param.setMealtimeTypeList(this.getMealtimeTypeList());
      param.setStartDate(this.getStartDate());
      param.setEndDate(this.getEndDate());
      param.setOrderTypeList(this.getOrderTypeList());
      if (CollUtil.isNotEmpty(userPlaceIdList) && CollUtil.isNotEmpty(this.placeIdList)) {
         CollUtil.intersectionDistinct(userPlaceIdList, this.placeIdList, new Collection[0]);
      } else if (CollUtil.isNotEmpty(userPlaceIdList)) {
         param.setDeliveryRelatedIdList(userPlaceIdList);
      } else {
         param.setDeliveryRelatedIdList(this.placeIdList);
      }

      return param;
   }

   public Long getIntervalId() {
      return this.intervalId;
   }

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

   public LocalDate getOrdGoodsDateStart() {
      return this.ordGoodsDateStart;
   }

   public LocalDate getOrdGoodsDateEnd() {
      return this.ordGoodsDateEnd;
   }

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

   public Long getReserveUserId() {
      return this.reserveUserId;
   }

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

   public Long getShopstallId() {
      return this.shopstallId;
   }

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

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

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

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

   public void setIntervalId(final Long intervalId) {
      this.intervalId = intervalId;
   }

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

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

   public void setOrdGoodsDateStart(final LocalDate ordGoodsDateStart) {
      this.ordGoodsDateStart = ordGoodsDateStart;
   }

   public void setOrdGoodsDateEnd(final LocalDate ordGoodsDateEnd) {
      this.ordGoodsDateEnd = ordGoodsDateEnd;
   }

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

   public void setReserveUserId(final Long reserveUserId) {
      this.reserveUserId = reserveUserId;
   }

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

   public void setShopstallId(final Long shopstallId) {
      this.shopstallId = shopstallId;
   }

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

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

   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;
   }

}
