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

import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.order.common.constants.OrderMobileSearchTypeEnum;
import com.bonus.canteen.core.pay.common.constants.PayStateEnum;
import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.canteen.core.common.page.PageDTO;
import com.bonus.canteen.core.order.common.constants.OrderRefundStateEnum;
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.OrderSearchParam;
import com.bonus.canteen.core.order.common.query.OrderQueryParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

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

@ApiModel("移动端订单列表查询DTO")
public class OrderListMobileDTO extends PageDTO implements OrderQueryParam {
   @ApiModelProperty("人员id")
   private Long custId;
   @ApiModelProperty("查询类型")
   private Integer searchType;
   @ApiModelProperty("订单类型 ")
   private Integer orderType;
   @ApiModelProperty("设备订单号")
   private String macOrderId;
   @ApiModelProperty("开始日期")
   private LocalDate startDate;
   @ApiModelProperty("结束日期")
   private LocalDate endDate;
   @ApiModelProperty("模糊搜索条件")
   private String searchText;
   @ApiModelProperty("支付状态")
   private List<Integer> payStateList;
   @ApiModelProperty("订单类型范围")
   private List<Integer> orderTypeList;

   @Override
   public List<Integer> getOrderTypeList() {
      return CollUtil.isNotEmpty(this.orderTypeList) ? this.orderTypeList : OrderTypeEnum.orderTypeListForMobileSearchType(this.orderType);
   }

   public OrderSearchParam convertToOrderSearchParam() {
      OrderSearchParam orderSearchParam = new OrderSearchParam();
      orderSearchParam.setCustId(this.custId);
      orderSearchParam.setMacOrderId(this.macOrderId);
      orderSearchParam.setStartDate(this.startDate);
      orderSearchParam.setEndDate(this.endDate);
      orderSearchParam.setCanteenSearchInfo(this.searchText);
      orderSearchParam.setPayStateList(this.payStateList);
      orderSearchParam.setOrderTypeList(this.getOrderTypeList());
      if (OrderMobileSearchTypeEnum.REFUNDED.getKey().equals(this.searchType)) {
         orderSearchParam.setOrderRefundStateList(CollUtil.toList(OrderRefundStateEnum.FINISH.getKey(), OrderRefundStateEnum.PART_SUCC.getKey()));
      } else if (OrderMobileSearchTypeEnum.WAIT_COMMEND.getKey().equals(this.searchType)) {
         orderSearchParam.setOrderStateList(CollUtil.toList(OrderStateEnum.FINISH.getKey()));
         orderSearchParam.setCommentState(LeConstants.COMMON_NO);
         orderSearchParam.setOrderTypeList(CollUtil.toList(OrderTypeEnum.CURR_MEAL.getKey(), OrderTypeEnum.RESERVE_MEAL.getKey(), OrderTypeEnum.BOOK_MEAL.getKey()));
      } else if (OrderMobileSearchTypeEnum.WAIT_PAY.getKey().equals(this.searchType)) {
         orderSearchParam.setPayStateList(CollUtil.toList(PayStateEnum.UN_PAY.getKey(), PayStateEnum.PART_PAY.getKey()));
      }

      return orderSearchParam;
   }

   @Override
   public Long getCustId() {
      return this.custId;
   }

   public Integer getSearchType() {
      return this.searchType;
   }

   @Override
   public Integer getOrderType() {
      return this.orderType;
   }

   @Override
   public String getMacOrderId() {
      return this.macOrderId;
   }

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

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

   public String getSearchText() {
      return this.searchText;
   }

   public List<Integer> getPayStateList() {
      return this.payStateList;
   }

   public void setCustId(final Long custId) {
      this.custId = custId;
   }

   public void setSearchType(final Integer searchType) {
      this.searchType = searchType;
   }

   public void setOrderType(final Integer orderType) {
      this.orderType = orderType;
   }

   public void setMacOrderId(final String macOrderId) {
      this.macOrderId = macOrderId;
   }

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

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

   public void setSearchText(final String searchText) {
      this.searchText = searchText;
   }

   public void setPayStateList(final List<Integer> payStateList) {
      this.payStateList = payStateList;
   }

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

}
