package com.bonus.canteen.core.report.bill.model;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bonus.canteen.core.pay.channel.bnj.po.BNJFile;
import com.bonus.canteen.core.pay.common.constants.PayChannelEnum;
import com.bonus.canteen.core.pay.common.constants.PayTypeEnum;
import com.bonus.canteen.core.pay.common.constants.TradeTypeEnum;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@TableName("report_order_channel_bill")
public class ReportOrderChannelBill {
   @TableId
   private String merOrderNo;
   private String orderNo;
   private LocalDate orderDate;
   private LocalDateTime orderTime;
   private BigDecimal shouldAmt;
   private BigDecimal actualAmt;
   private BigDecimal discountableAmt;
   private BigDecimal refundAmt;
   private Integer tradeType;
   private Integer tradeState;
   private String openid;
   private Integer payType;
   private Integer payChannel;
   private BigDecimal feeRate;
   private BigDecimal fee;
   private BigDecimal channelFeeRate;
   private BigDecimal channelFee;
   private LocalDateTime createTime;
   private LocalDateTime updateTime;
   private Long canteenId;

   public static ReportOrderChannelBill from(BNJFile file) {
      ReportOrderChannelBill bill = new ReportOrderChannelBill();
      bill.setOrderNo(file.getChannelTranNo());
      bill.setMerOrderNo(file.getTranNo());
      bill.setOrderDate(LocalDate.parse(file.getTranTime(), DateTimeFormatter.BASIC_ISO_DATE));
      bill.setOrderTime(LocalDateTime.parse(file.getTranTime(), DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
      bill.setPayType(PayTypeEnum.ACC_BNJ_PAY.getKey());
      bill.setPayChannel(PayChannelEnum.BNJ.getKey());
      bill.setTradeType(TradeTypeEnum.CONSUME.getKey());
      bill.setTradeState(bill.switchState(file.getStatus()));
      if (file.getTranType().equals("02")) {
         bill.setRefundAmt(new BigDecimal(file.getTranAmount()));
      } else {
         bill.setShouldAmt(new BigDecimal(file.getTranAmount()));
         bill.setActualAmt(new BigDecimal(file.getTranAmount()));
      }

      return bill;
   }

   private int switchState(String state) {
      byte var10000;
      switch (state) {
         case "00":
         case "02":
         case "03":
         case "04":
            var10000 = 3;
            break;
         case "01":
            var10000 = 4;
            break;
         case "99":
         case "80":
            var10000 = 2;
            break;
         default:
            var10000 = 5;
      }

      return var10000;
   }

   public String getMerOrderNo() {
      return this.merOrderNo;
   }

   public String getOrderNo() {
      return this.orderNo;
   }

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

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

   public BigDecimal getShouldAmt() {
      return this.shouldAmt;
   }

   public BigDecimal getActualAmt() {
      return this.actualAmt;
   }

   public BigDecimal getDiscountableAmt() {
      return this.discountableAmt;
   }

   public BigDecimal getRefundAmt() {
      return this.refundAmt;
   }

   public Integer getTradeType() {
      return this.tradeType;
   }

   public Integer getTradeState() {
      return this.tradeState;
   }

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

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

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

   public BigDecimal getFeeRate() {
      return this.feeRate;
   }

   public BigDecimal getFee() {
      return this.fee;
   }

   public BigDecimal getChannelFeeRate() {
      return this.channelFeeRate;
   }

   public BigDecimal getChannelFee() {
      return this.channelFee;
   }

   public LocalDateTime getCreateTime() {
      return this.createTime;
   }

   public LocalDateTime getUpdateTime() {
      return this.updateTime;
   }

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

   public void setMerOrderNo(final String merOrderNo) {
      this.merOrderNo = merOrderNo;
   }

   public void setOrderNo(final String orderNo) {
      this.orderNo = orderNo;
   }

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

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

   public void setShouldAmt(final BigDecimal shouldAmt) {
      this.shouldAmt = shouldAmt;
   }

   public void setActualAmt(final BigDecimal actualAmt) {
      this.actualAmt = actualAmt;
   }

   public void setDiscountableAmt(final BigDecimal discountableAmt) {
      this.discountableAmt = discountableAmt;
   }

   public void setRefundAmt(final BigDecimal refundAmt) {
      this.refundAmt = refundAmt;
   }

   public void setTradeType(final Integer tradeType) {
      this.tradeType = tradeType;
   }

   public void setTradeState(final Integer tradeState) {
      this.tradeState = tradeState;
   }

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

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

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

   public void setFeeRate(final BigDecimal feeRate) {
      this.feeRate = feeRate;
   }

   public void setFee(final BigDecimal fee) {
      this.fee = fee;
   }

   public void setChannelFeeRate(final BigDecimal channelFeeRate) {
      this.channelFeeRate = channelFeeRate;
   }

   public void setChannelFee(final BigDecimal channelFee) {
      this.channelFee = channelFee;
   }

   public void setCreateTime(final LocalDateTime createTime) {
      this.createTime = createTime;
   }

   public void setUpdateTime(final LocalDateTime updateTime) {
      this.updateTime = updateTime;
   }

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


   public ReportOrderChannelBill() {
   }

   public ReportOrderChannelBill(final String merOrderNo, final String orderNo, final LocalDate orderDate, final LocalDateTime orderTime, final BigDecimal shouldAmt, final BigDecimal actualAmt, final BigDecimal discountableAmt, final BigDecimal refundAmt, final Integer tradeType, final Integer tradeState, final String openid, final Integer payType, final Integer payChannel, final BigDecimal feeRate, final BigDecimal fee, final BigDecimal channelFeeRate, final BigDecimal channelFee, final LocalDateTime createTime, final LocalDateTime updateTime, final Long canteenId) {
      this.merOrderNo = merOrderNo;
      this.orderNo = orderNo;
      this.orderDate = orderDate;
      this.orderTime = orderTime;
      this.shouldAmt = shouldAmt;
      this.actualAmt = actualAmt;
      this.discountableAmt = discountableAmt;
      this.refundAmt = refundAmt;
      this.tradeType = tradeType;
      this.tradeState = tradeState;
      this.openid = openid;
      this.payType = payType;
      this.payChannel = payChannel;
      this.feeRate = feeRate;
      this.fee = fee;
      this.channelFeeRate = channelFeeRate;
      this.channelFee = channelFee;
      this.createTime = createTime;
      this.updateTime = updateTime;
      this.canteenId = canteenId;
   }
}
