package com.bonus.canteen.core.order.mq.po;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import com.bonus.canteen.core.order.common.model.OrderAmountDetail;
import com.bonus.canteen.core.order.common.model.OrderDelivery;
import com.bonus.canteen.core.order.common.model.OrderDetail;
import com.bonus.canteen.core.order.common.model.OrderInfo;
import com.bonus.canteen.core.order.weight.dto.OrderWeightPlaceDetailDTO;
import com.bonus.canteen.core.pay.api.dto.UnifyPayDTO;
import com.bonus.canteen.core.pay.api.vo.UnifyPayVO;
import com.bonus.canteen.core.order.common.model.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class OrderSavePO {
   private String traceId;
   private Long tenantId;
   private String macOrderId;
   private UnifyPayDTO payDTO;
   private UnifyPayVO payVO;
   private List<OrderInfo> orderInfoList = CollUtil.newArrayList(new OrderInfo[0]);
   private List<OrderDetail> orderDetailList = CollUtil.newArrayList(new OrderDetail[0]);
   private List<OrderDelivery> orderDeliveryList = CollUtil.newArrayList(new OrderDelivery[0]);
   private List<OrderAmountChange> amountChangeList = CollUtil.newArrayList(new OrderAmountChange[0]);
   private List<OrderAmountDetail> amountDetailList = CollUtil.newArrayList(new OrderAmountDetail[0]);
   private List<OrderWeightPlaceDetailDTO> weightDetailList = CollUtil.newArrayList(new OrderWeightPlaceDetailDTO[0]);
   private Map<Long, Long> shoppingCartIdMapByDetailId = MapUtil.newHashMap();

   public List<OrderDetail> orderDetailListByOrderId(Long orderId) {
      return (List)this.orderDetailList.stream().filter((orderDetail) -> {
         return orderDetail.getOrderId().equals(orderId);
      }).collect(Collectors.toList());
   }

   public static OrderSavePO byLockKey(String lockKey) {
      OrderSavePO orderSavePO = new OrderSavePO();
      orderSavePO.setMacOrderId(lockKey);
      return orderSavePO;
   }

   public static OrderSavePO byOrderInfo(List<OrderInfo> orderInfoList, List<OrderDetail> orderDetailList, List<OrderDelivery> orderDeliveryList) {
      return byOrderInfo(orderInfoList, orderDetailList, orderDeliveryList, (List)null);
   }

   public static OrderSavePO byOrderInfo(List<OrderInfo> orderInfoList, List<OrderDetail> orderDetailList, List<OrderDelivery> orderDeliveryList, List<OrderAmountDetail> amountDetailList) {
      OrderSavePO orderSavePO = new OrderSavePO();
      orderSavePO.setOrderInfoList((List)(orderInfoList != null ? orderInfoList : CollUtil.newArrayList(new OrderInfo[0])));
      orderSavePO.setOrderDetailList((List)(orderDetailList != null ? orderDetailList : CollUtil.newArrayList(new OrderDetail[0])));
      orderSavePO.setOrderDeliveryList((List)(orderDeliveryList != null ? orderDeliveryList : CollUtil.newArrayList(new OrderDelivery[0])));
      orderSavePO.setAmountDetailList((List)(amountDetailList != null ? amountDetailList : CollUtil.newArrayList(new OrderAmountDetail[0])));
      orderSavePO.setMacOrderId(CollUtil.isNotEmpty(orderInfoList) ? ((OrderInfo)orderInfoList.get(0)).getMacOrderId() : null);
      return orderSavePO;
   }

   public String getTraceId() {
      return this.traceId;
   }

   public Long getTenantId() {
      return this.tenantId;
   }

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

   public UnifyPayDTO getPayDTO() {
      return this.payDTO;
   }

   public UnifyPayVO getPayVO() {
      return this.payVO;
   }

   public List<OrderInfo> getOrderInfoList() {
      return this.orderInfoList;
   }

   public List<OrderDetail> getOrderDetailList() {
      return this.orderDetailList;
   }

   public List<OrderDelivery> getOrderDeliveryList() {
      return this.orderDeliveryList;
   }

   public List<OrderAmountChange> getAmountChangeList() {
      return this.amountChangeList;
   }

   public List<OrderAmountDetail> getAmountDetailList() {
      return this.amountDetailList;
   }

   public List<OrderWeightPlaceDetailDTO> getWeightDetailList() {
      return this.weightDetailList;
   }

   public Map<Long, Long> getShoppingCartIdMapByDetailId() {
      return this.shoppingCartIdMapByDetailId;
   }

   public void setTraceId(final String traceId) {
      this.traceId = traceId;
   }

   public void setTenantId(final Long tenantId) {
      this.tenantId = tenantId;
   }

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

   public void setPayDTO(final UnifyPayDTO payDTO) {
      this.payDTO = payDTO;
   }

   public void setPayVO(final UnifyPayVO payVO) {
      this.payVO = payVO;
   }

   public void setOrderInfoList(final List<OrderInfo> orderInfoList) {
      this.orderInfoList = orderInfoList;
   }

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

   public void setOrderDeliveryList(final List<OrderDelivery> orderDeliveryList) {
      this.orderDeliveryList = orderDeliveryList;
   }

   public void setAmountChangeList(final List<OrderAmountChange> amountChangeList) {
      this.amountChangeList = amountChangeList;
   }

   public void setAmountDetailList(final List<OrderAmountDetail> amountDetailList) {
      this.amountDetailList = amountDetailList;
   }

   public void setWeightDetailList(final List<OrderWeightPlaceDetailDTO> weightDetailList) {
      this.weightDetailList = weightDetailList;
   }

   public void setShoppingCartIdMapByDetailId(final Map<Long, Long> shoppingCartIdMapByDetailId) {
      this.shoppingCartIdMapByDetailId = shoppingCartIdMapByDetailId;
   }

}
