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

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import com.bonus.canteen.core.common.encrypt.LeNiuDecryptDataProcess;
import com.bonus.canteen.core.common.encrypt.LeNiuDecryptField;
import com.bonus.canteen.core.device.android.buffet.vo.BuffetOrdDetailVO;
import com.bonus.canteen.core.device.manage.controller.deprecated.vo.MacCustInfoHealthyVo;
import com.bonus.canteen.core.nutrition.common.vo.NutrReferenceIntakeVO;
import com.bonus.canteen.core.order.mobile.vo.OrderNutrientInfoVO;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@LeNiuDecryptDataProcess
public class BuffetBindVo {
   @ApiModelProperty("所有订单")
   private List<MacWeighConsumVO> weighConsumReportList = new ArrayList();
   @ApiModelProperty("所有订单明细")
   private List<BuffetOrdDetailVO> buffetOrdDetailVOList = new ArrayList();
   @ApiModelProperty("餐盘物理卡号")
   private @NotNull(
   message = "餐盘id不能为空"
) String serialNum;
   @ApiModelProperty("人员id")
   private Long custId;
   @ApiModelProperty("绑定类型 1设备2微信3设备绑定调用第三方支付4第三方绑定")
   private Integer bindType;
   @ApiModelProperty("设备是否关注余额1关注2不关注")
   private Integer ifcareblance;
   @ApiModelProperty("设备订单号")
   private String macOrdId;
   @ApiModelProperty("绑盘时间")
   @JsonSerialize(
      using = LocalDateTimeSerializer.class
   )
   @JsonDeserialize(
      using = LocalDateTimeDeserializer.class
   )
   private LocalDateTime localDateTimebind;
   @ApiModelProperty("账户余额(个人钱包+补贴钱包) 单位分")
   private BigDecimal accBal;
   @ApiModelProperty("是否签约")
   private Integer ifContract;
   @ApiModelProperty("人员健康信息")
   private MacCustInfoHealthyVo macCustInfoHealthyVo;
   @ApiModelProperty("人员摄入之建议")
   private NutrReferenceIntakeVO nutrReferenceIntakeVO;
   @ApiModelProperty("核身方式")
   private Integer nuClearMode;
   @ApiModelProperty("绑定状态")
   private Integer bindState;
   @ApiModelProperty("openid")
   private String openid;
   @ApiModelProperty("总金额")
   private Integer amount;
   @ApiModelProperty("总金额（兼容）")
   private Integer realAmount;
   @ApiModelProperty("支付方式")
   private Integer payType;
   @ApiModelProperty("折扣")
   private BigDecimal discount;
   @ApiModelProperty("已优惠")
   private BigDecimal discountAmount;
   @ApiModelProperty("上一次拿菜设备sn")
   private @NotNull(
   message = "上一次拿菜设备sn"
) String lastDeviceSn;
   @ApiModelProperty("设备是否余额不足报警 1是2否")
   private String ifblancealarm;
   @ApiModelProperty("余额不足报警金额")
   private String alarmblance;
   @ApiModelProperty("人员姓名")
   @LeNiuDecryptField
   private String openidName;
   @ApiModelProperty("绑盘有效时间")
   private Integer weighingValidTime;
   @ApiModelProperty("绑盘有效时间")
   private Integer weighingValidTimeOnline;
   @ApiModelProperty("取餐后自动结账时长 默认10分钟  最后一次那才后开始计时")
   private Integer waitingPayTime;
   @ApiModelProperty("订单营养信息")
   private OrderNutrientInfoVO nutrientInfo;
   @ApiModelProperty("代扣支付方式")
   private Integer payTypeHold;

   public Integer getRealAmount() {
      return this.amount != null ? this.amount : 0;
   }

   public BigDecimal getDiscount() {
      return this.discount != null ? this.discount : BigDecimal.ONE;
   }

   public BigDecimal getDiscountAmount() {
      return NumberUtil.mul(this.getRealAmount(), NumberUtil.sub(BigDecimal.ONE, this.getDiscount()));
   }

   public void setWeighConsumReportList(List<MacWeighConsumVO> weighConsumReportList) {
      this.weighConsumReportList = weighConsumReportList;
      if (CollUtil.isNotEmpty(weighConsumReportList)) {
         this.buffetOrdDetailVOList = (List)weighConsumReportList.stream().map(BuffetOrdDetailVO::of).collect(Collectors.toList());
      }

   }

   public List<MacWeighConsumVO> getWeighConsumReportList() {
      return this.weighConsumReportList;
   }

   public List<BuffetOrdDetailVO> getBuffetOrdDetailVOList() {
      return this.buffetOrdDetailVOList;
   }

   public String getSerialNum() {
      return this.serialNum;
   }

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

   public Integer getBindType() {
      return this.bindType;
   }

   public Integer getIfcareblance() {
      return this.ifcareblance;
   }

   public String getMacOrdId() {
      return this.macOrdId;
   }

   public LocalDateTime getLocalDateTimebind() {
      return this.localDateTimebind;
   }

   public BigDecimal getAccBal() {
      return this.accBal;
   }

   public Integer getIfContract() {
      return this.ifContract;
   }

   public MacCustInfoHealthyVo getMacCustInfoHealthyVo() {
      return this.macCustInfoHealthyVo;
   }

   public NutrReferenceIntakeVO getNutrReferenceIntakeVO() {
      return this.nutrReferenceIntakeVO;
   }

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

   public Integer getBindState() {
      return this.bindState;
   }

   public String getOpenid() {
      return this.openid;
   }

   public Integer getAmount() {
      return this.amount;
   }

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

   public String getLastDeviceSn() {
      return this.lastDeviceSn;
   }

   public String getIfblancealarm() {
      return this.ifblancealarm;
   }

   public String getAlarmblance() {
      return this.alarmblance;
   }

   public String getOpenidName() {
      return this.openidName;
   }

   public Integer getWeighingValidTime() {
      return this.weighingValidTime;
   }

   public Integer getWeighingValidTimeOnline() {
      return this.weighingValidTimeOnline;
   }

   public Integer getWaitingPayTime() {
      return this.waitingPayTime;
   }

   public OrderNutrientInfoVO getNutrientInfo() {
      return this.nutrientInfo;
   }

   public Integer getPayTypeHold() {
      return this.payTypeHold;
   }

   public BuffetBindVo setBuffetOrdDetailVOList(final List<BuffetOrdDetailVO> buffetOrdDetailVOList) {
      this.buffetOrdDetailVOList = buffetOrdDetailVOList;
      return this;
   }

   public BuffetBindVo setSerialNum(final String serialNum) {
      this.serialNum = serialNum;
      return this;
   }

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

   public BuffetBindVo setBindType(final Integer bindType) {
      this.bindType = bindType;
      return this;
   }

   public BuffetBindVo setIfcareblance(final Integer ifcareblance) {
      this.ifcareblance = ifcareblance;
      return this;
   }

   public BuffetBindVo setMacOrdId(final String macOrdId) {
      this.macOrdId = macOrdId;
      return this;
   }

   @JsonDeserialize(
      using = LocalDateTimeDeserializer.class
   )
   public BuffetBindVo setLocalDateTimebind(final LocalDateTime localDateTimebind) {
      this.localDateTimebind = localDateTimebind;
      return this;
   }

   public BuffetBindVo setAccBal(final BigDecimal accBal) {
      this.accBal = accBal;
      return this;
   }

   public BuffetBindVo setIfContract(final Integer ifContract) {
      this.ifContract = ifContract;
      return this;
   }

   public BuffetBindVo setMacCustInfoHealthyVo(final MacCustInfoHealthyVo macCustInfoHealthyVo) {
      this.macCustInfoHealthyVo = macCustInfoHealthyVo;
      return this;
   }

   public BuffetBindVo setNutrReferenceIntakeVO(final NutrReferenceIntakeVO nutrReferenceIntakeVO) {
      this.nutrReferenceIntakeVO = nutrReferenceIntakeVO;
      return this;
   }

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

   public BuffetBindVo setBindState(final Integer bindState) {
      this.bindState = bindState;
      return this;
   }

   public BuffetBindVo setOpenid(final String openid) {
      this.openid = openid;
      return this;
   }

   public BuffetBindVo setAmount(final Integer amount) {
      this.amount = amount;
      return this;
   }

   public BuffetBindVo setRealAmount(final Integer realAmount) {
      this.realAmount = realAmount;
      return this;
   }

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

   public BuffetBindVo setDiscount(final BigDecimal discount) {
      this.discount = discount;
      return this;
   }

   public BuffetBindVo setDiscountAmount(final BigDecimal discountAmount) {
      this.discountAmount = discountAmount;
      return this;
   }

   public BuffetBindVo setLastDeviceSn(final String lastDeviceSn) {
      this.lastDeviceSn = lastDeviceSn;
      return this;
   }

   public BuffetBindVo setIfblancealarm(final String ifblancealarm) {
      this.ifblancealarm = ifblancealarm;
      return this;
   }

   public BuffetBindVo setAlarmblance(final String alarmblance) {
      this.alarmblance = alarmblance;
      return this;
   }

   public BuffetBindVo setOpenidName(final String openidName) {
      this.openidName = openidName;
      return this;
   }

   public BuffetBindVo setWeighingValidTime(final Integer weighingValidTime) {
      this.weighingValidTime = weighingValidTime;
      return this;
   }

   public BuffetBindVo setWeighingValidTimeOnline(final Integer weighingValidTimeOnline) {
      this.weighingValidTimeOnline = weighingValidTimeOnline;
      return this;
   }

   public BuffetBindVo setWaitingPayTime(final Integer waitingPayTime) {
      this.waitingPayTime = waitingPayTime;
      return this;
   }

   public BuffetBindVo setNutrientInfo(final OrderNutrientInfoVO nutrientInfo) {
      this.nutrientInfo = nutrientInfo;
      return this;
   }

   public BuffetBindVo setPayTypeHold(final Integer payTypeHold) {
      this.payTypeHold = payTypeHold;
      return this;
   }

}
