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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.bonus.canteen.core.account.v3.api.vo.AccExceptionRecordApiVO;
import com.bonus.canteen.core.account.v3.constants.AccExceptionRecordStatusEnum;
import com.bonus.canteen.core.common.constant.NuclearModeEnum;
import com.bonus.canteen.core.common.enums.DeliveryTypeEnum;
import com.bonus.canteen.core.common.enums.SourceTypeEnum;
import com.bonus.canteen.core.common.utils.CustomNumberConverter;
import com.bonus.canteen.core.common.utils.SysUtil;
import com.bonus.canteen.core.customer.constants.OrderTypeEnum;
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.vo.OrderDetailVO;
import com.bonus.canteen.core.order.common.vo.OrderDetailWithMachine;
import com.bonus.canteen.core.order.mobile.vo.OrderAmountChangeVO;
import com.bonus.canteen.core.pay.api.vo.OrderTradeInfoVO;
import com.bonus.canteen.core.pay.common.constants.PayStateEnum;
import com.bonus.common.houqin.constant.LeConstants;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public class OrderInfoWebVO implements OrderDetailWithMachine {
   @ExcelProperty(
      value = {"订单类型"},
      order = 0,
      converter = OrderTypeEnum.ExcelConvertor.class
   )
   private Integer orderType;
   private Integer ifOnline;
   @ExcelIgnore
   private Long custId;
   @ExcelProperty(
      value = {"用户姓名"},
      order = 1
   )
   private String custName;
   @ExcelProperty(
      value = {"用户编号"},
      order = 1
   )
   private String custNum;
   @ExcelIgnore
   private Long operatorId;
   @ExcelProperty(
      value = {"点餐员姓名"},
      order = 7
   )
   private String operatorName;
   @ExcelIgnore
   private Long cashierId;
   @ExcelProperty(
      value = {"收银员姓名"},
      order = 7
   )
   private String cashierName;
   @ExcelProperty(
      value = {"手机号"},
      order = 2
   )
   private String mobile;
   @ExcelProperty(
      value = {"组织名称"},
      order = 3
   )
   private String orgFullName;
   @ExcelProperty(
      value = {"用户类别"},
      order = 4
   )
   private String psnTypeName;
   @ExcelProperty(
      value = {"订单来源"},
      order = 5,
      converter = SourceTypeEnum.ExcelConvertor.class
   )
   private Integer sourceType;
   @ExcelProperty(
      value = {"设备sn码"},
      order = 6
   )
   private String machineSn;
   @ExcelIgnore
   private String machineNum;
   @ExcelIgnore
   private String deviceName;
   @ExcelIgnore
   private String deviceModel;
   @ExcelProperty(
      value = {"订单号"},
      order = 7
   )
   private Long orderId;
   @ExcelProperty(
      value = {"设备订单号"},
      order = 8
   )
   private String macOrderId;
   @ExcelProperty(
      value = {"就餐日期"},
      order = 9
   )
   private LocalDate orderDate;
   @ExcelProperty(
      value = {"下单时间"},
      order = 10
   )
   private LocalDateTime orderTime;
   @ExcelProperty(
      value = {"支付时间"},
      order = 11
   )
   private LocalDateTime payTime;
   @ExcelIgnore
   private Long areaId;
   @ExcelProperty(
      value = {"所属区域"},
      order = 12
   )
   private String areaName;
   @ExcelIgnore
   private Long canteenId;
   @ExcelProperty(
      value = {"所属食堂"},
      order = 12
   )
   private String canteenName;
   @ExcelIgnore
   private Long stallId;
   @ExcelProperty(
      value = {"所属档口"},
      order = 13
   )
   private String stallName;
   @ExcelIgnore
   private Long roomId;
   @ExcelProperty(
      value = {"包间或餐桌名称"},
      order = 13
   )
   private String roomName;
   @ExcelIgnore
   private Integer mealtimeType;
   @ExcelProperty(
      value = {"餐次名称"},
      order = 14
   )
   private String mealtimeName;
   @ExcelProperty(
      value = {"订单金额"},
      order = 16,
      converter = CustomNumberConverter.class
   )
   private BigDecimal payableAmount;
   @ExcelProperty(
      value = {"上浮/优惠金额"},
      order = 16,
      converter = CustomNumberConverter.class
   )
   private BigDecimal discountsAmount;
   @ExcelProperty(
      value = {"餐券支付金额"},
      order = 17,
      converter = CustomNumberConverter.class
   )
   private BigDecimal couponAmount;
   @ExcelProperty(
      value = {"餐券名称"},
      order = 18
   )
   private String couponName;
   @ExcelProperty(
      value = {"核身方式"},
      order = 19,
      converter = NuclearModeEnum.ExcelConvertor.class
   )
   private Integer nuClearMode;
   @ExcelProperty(
      value = {"实付金额"},
      order = 20,
      converter = CustomNumberConverter.class
   )
   private BigDecimal realAmount;
   @ExcelProperty(
      value = {"已退金额"},
      order = 28,
      converter = CustomNumberConverter.class
   )
   private BigDecimal refundAmount;
   @ExcelProperty(
      value = {"支付方式"},
      order = 21
   )
   private Integer payType;
   @ExcelProperty(
      value = {"支付方式"},
      order = 15
   )
   private String payTypesStr;
   @ExcelIgnore
   private Integer payChannel;
   @ExcelIgnore
   private Integer deductionType;
   @ExcelProperty(
      value = {"配送方式"},
      order = 22,
      converter = DeliveryTypeEnum.ExcelConvertor.class
   )
   private Integer deliveryType;
   @ExcelProperty(
      value = {"订单状态"},
      order = 23,
      converter = OrderStateEnum.ExcelConvertor.class
   )
   private Integer orderState;
   @ExcelIgnore
   private Integer payState;
   @ExcelProperty(
      value = {"订单退款状态"},
      order = 24
   )
   private Integer orderRefundState;
   private Integer dishesState;
   @ExcelProperty(
      value = {"配送费"},
      order = 25,
      converter = CustomNumberConverter.class
   )
   private BigDecimal deliveryAmount;
   @ExcelProperty(
      value = {"包装费"},
      order = 26,
      converter = CustomNumberConverter.class
   )
   private BigDecimal packingAmount;
   @ExcelIgnore
   private String imgUrl;
   @ExcelProperty(
      value = {"备注"},
      order = 27
   )
   private String remark;
   @ExcelProperty(
      value = {"取餐码"},
      order = 28
   )
   private String mealCode;
   @ExcelProperty(
      value = {"菜品明细"},
      order = 15
   )
   private String dishDetailStr;
   @ExcelProperty(
      value = {"已退菜品"},
      order = 27
   )
   private String refundDishDetailStr;
   @ExcelIgnore
   private String orderPhotoUrl;
   @ExcelProperty(
      value = {"订单状态"},
      order = 23,
      converter = OrderStateMixEnum.ExcelConvertor.class
   )
   private Integer orderStateMix;
   @ExcelIgnore
   private Long accExceptionRecordId;
   @ExcelIgnore
   private Integer accExceptionRecordProcessed;
   private String outTradeNo;
   private String partPayReason;
   @ExcelIgnore
   private List<OrderAmountChangeVO> amountChangeList;
   @ExcelIgnore
   private List<OrderDetailVO> orderDetailList;
   @ExcelIgnore
   private List<OrderAmountDetailWebVO> amountDetailList;

   public String getImgUrl() {
      return SysUtil.getCutFileUrl(this.imgUrl);
   }

   public Integer getOrderStateMix() {
      return OrderStateMixEnum.mixStateBy(this.getOrderState(), this.getPayState(), this.getOrderRefundState());
   }

   public void setOrderPhotoUrl(String orderPhotoUrl) {
      this.orderPhotoUrl = SysUtil.getCutFileUrl(orderPhotoUrl);
   }

   public static OrderInfoWebVO of(OrderListWebVO listVO) {
      return (OrderInfoWebVO)BeanUtil.copyProperties(listVO, OrderInfoWebVO.class, new String[0]);
   }

   public void setMachineName(String machineName) {
      this.deviceName = machineName;
   }

   public void fillOrderTradeInfo(OrderTradeInfoVO orderTradeInfoVO) {
      if (orderTradeInfoVO != null) {
         OrderTradeInfoVO.Trade lastTrade = orderTradeInfoVO.findLastTrade();
         if (lastTrade != null) {
            this.outTradeNo = lastTrade.getOutTradeNo();
            this.partPayReason = !PayStateEnum.isPartPayState(lastTrade.getTradeState()) && !PayStateEnum.isPayingState(lastTrade.getTradeState()) ? null : lastTrade.getTradeResult();
         }

         AccExceptionRecordApiVO accException = orderTradeInfoVO.findAccException();
         List<Integer> matchedStates = CollUtil.toList(new Integer[]{AccExceptionRecordStatusEnum.FAIL.getKey(), AccExceptionRecordStatusEnum.SECOND_SUCC.getKey()});
         if (accException != null && matchedStates.contains(accException.getRecordStatus())) {
            this.accExceptionRecordId = accException.getId();
            this.accExceptionRecordProcessed = AccExceptionRecordStatusEnum.SECOND_SUCC.getKey().equals(accException.getRecordStatus()) ? LeConstants.COMMON_YES : LeConstants.COMMON_NO;
         }

      }
   }

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

   public Integer getIfOnline() {
      return this.ifOnline;
   }

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

   public String getCustName() {
      return this.custName;
   }

   public String getCustNum() {
      return this.custNum;
   }

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

   public String getOperatorName() {
      return this.operatorName;
   }

   public Long getCashierId() {
      return this.cashierId;
   }

   public String getCashierName() {
      return this.cashierName;
   }

   public String getMobile() {
      return this.mobile;
   }

   public String getOrgFullName() {
      return this.orgFullName;
   }

   public String getPsnTypeName() {
      return this.psnTypeName;
   }

   public Integer getSourceType() {
      return this.sourceType;
   }

   public String getMachineSn() {
      return this.machineSn;
   }

   public String getMachineNum() {
      return this.machineNum;
   }

   public String getDeviceName() {
      return this.deviceName;
   }

   public String getDeviceModel() {
      return this.deviceModel;
   }

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

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

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

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

   public LocalDateTime getPayTime() {
      return this.payTime;
   }

   public Long getAreaId() {
      return this.areaId;
   }

   public String getAreaName() {
      return this.areaName;
   }

   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 Long getRoomId() {
      return this.roomId;
   }

   public String getRoomName() {
      return this.roomName;
   }

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

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

   public BigDecimal getPayableAmount() {
      return this.payableAmount;
   }

   public BigDecimal getDiscountsAmount() {
      return this.discountsAmount;
   }

   public BigDecimal getCouponAmount() {
      return this.couponAmount;
   }

   public String getCouponName() {
      return this.couponName;
   }

   public Integer getNuClearMode() {
      return this.nuClearMode;
   }

   public BigDecimal getRealAmount() {
      return this.realAmount;
   }

   public BigDecimal getRefundAmount() {
      return this.refundAmount;
   }

   public Integer getPayType() {
      return this.payType;
   }

   public String getPayTypesStr() {
      return this.payTypesStr;
   }

   public Integer getPayChannel() {
      return this.payChannel;
   }

   public Integer getDeductionType() {
      return this.deductionType;
   }

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

   public Integer getOrderState() {
      return this.orderState;
   }

   public Integer getPayState() {
      return this.payState;
   }

   public Integer getOrderRefundState() {
      return this.orderRefundState;
   }

   public Integer getDishesState() {
      return this.dishesState;
   }

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

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

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

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

   public String getDishDetailStr() {
      return this.dishDetailStr;
   }

   public String getRefundDishDetailStr() {
      return this.refundDishDetailStr;
   }

   public String getOrderPhotoUrl() {
      return this.orderPhotoUrl;
   }

   public Long getAccExceptionRecordId() {
      return this.accExceptionRecordId;
   }

   public Integer getAccExceptionRecordProcessed() {
      return this.accExceptionRecordProcessed;
   }

   public String getOutTradeNo() {
      return this.outTradeNo;
   }

   public String getPartPayReason() {
      return this.partPayReason;
   }

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

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

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

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

   public void setIfOnline(final Integer ifOnline) {
      this.ifOnline = ifOnline;
   }

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

   public void setCustName(final String custName) {
      this.custName = custName;
   }

   public void setCustNum(final String custNum) {
      this.custNum = custNum;
   }

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

   public void setOperatorName(final String operatorName) {
      this.operatorName = operatorName;
   }

   public void setCashierId(final Long cashierId) {
      this.cashierId = cashierId;
   }

   public void setCashierName(final String cashierName) {
      this.cashierName = cashierName;
   }

   public void setMobile(final String mobile) {
      this.mobile = mobile;
   }

   public void setOrgFullName(final String orgFullName) {
      this.orgFullName = orgFullName;
   }

   public void setPsnTypeName(final String psnTypeName) {
      this.psnTypeName = psnTypeName;
   }

   public void setSourceType(final Integer sourceType) {
      this.sourceType = sourceType;
   }

   public void setMachineSn(final String machineSn) {
      this.machineSn = machineSn;
   }

   public void setMachineNum(final String machineNum) {
      this.machineNum = machineNum;
   }

   public void setDeviceName(final String deviceName) {
      this.deviceName = deviceName;
   }

   public void setDeviceModel(final String deviceModel) {
      this.deviceModel = deviceModel;
   }

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

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

   public void setOrderDate(final LocalDate orderDate) {
      this.orderDate = orderDate;
   }

   public void setOrderTime(final LocalDateTime orderTime) {
      this.orderTime = orderTime;
   }

   public void setPayTime(final LocalDateTime payTime) {
      this.payTime = payTime;
   }

   public void setAreaId(final Long areaId) {
      this.areaId = areaId;
   }

   public void setAreaName(final String areaName) {
      this.areaName = areaName;
   }

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

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

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

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

   public void setRoomId(final Long roomId) {
      this.roomId = roomId;
   }

   public void setRoomName(final String roomName) {
      this.roomName = roomName;
   }

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

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

   public void setPayableAmount(final BigDecimal payableAmount) {
      this.payableAmount = payableAmount;
   }

   public void setDiscountsAmount(final BigDecimal discountsAmount) {
      this.discountsAmount = discountsAmount;
   }

   public void setCouponAmount(final BigDecimal couponAmount) {
      this.couponAmount = couponAmount;
   }

   public void setCouponName(final String couponName) {
      this.couponName = couponName;
   }

   public void setNuClearMode(final Integer nuClearMode) {
      this.nuClearMode = nuClearMode;
   }

   public void setRealAmount(final BigDecimal realAmount) {
      this.realAmount = realAmount;
   }

   public void setRefundAmount(final BigDecimal refundAmount) {
      this.refundAmount = refundAmount;
   }

   public void setPayType(final Integer payType) {
      this.payType = payType;
   }

   public void setPayTypesStr(final String payTypesStr) {
      this.payTypesStr = payTypesStr;
   }

   public void setPayChannel(final Integer payChannel) {
      this.payChannel = payChannel;
   }

   public void setDeductionType(final Integer deductionType) {
      this.deductionType = deductionType;
   }

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

   public void setOrderState(final Integer orderState) {
      this.orderState = orderState;
   }

   public void setPayState(final Integer payState) {
      this.payState = payState;
   }

   public void setOrderRefundState(final Integer orderRefundState) {
      this.orderRefundState = orderRefundState;
   }

   public void setDishesState(final Integer dishesState) {
      this.dishesState = dishesState;
   }

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

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

   public void setImgUrl(final String imgUrl) {
      this.imgUrl = imgUrl;
   }

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

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

   public void setDishDetailStr(final String dishDetailStr) {
      this.dishDetailStr = dishDetailStr;
   }

   public void setRefundDishDetailStr(final String refundDishDetailStr) {
      this.refundDishDetailStr = refundDishDetailStr;
   }

   public void setOrderStateMix(final Integer orderStateMix) {
      this.orderStateMix = orderStateMix;
   }

   public void setAccExceptionRecordId(final Long accExceptionRecordId) {
      this.accExceptionRecordId = accExceptionRecordId;
   }

   public void setAccExceptionRecordProcessed(final Integer accExceptionRecordProcessed) {
      this.accExceptionRecordProcessed = accExceptionRecordProcessed;
   }

   public void setOutTradeNo(final String outTradeNo) {
      this.outTradeNo = outTradeNo;
   }

   public void setPartPayReason(final String partPayReason) {
      this.partPayReason = partPayReason;
   }

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

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

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

}
