package com.bonus.canteen.core.order.common.model;

import com.baomidou.mybatisplus.annotation.TableName;
import com.bonus.canteen.core.pay.common.constants.PayChannelEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;

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

@TableName("order_amount_detail")
public class OrderAmountDetail {
   private Long amountDetailId;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd"
   )
   private LocalDate orderDate;
   private Long tradeChannelId;
   private Long orderId;
   private Long orderRefundId;
   private BigDecimal amount;
   private BigDecimal walletAmount;
   private BigDecimal subsidyAmount;
   private BigDecimal redEnvelopeAmount;
   private Integer amountDetailType;
   private Integer payType;
   private Integer payChannel;
   private String remark;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   private LocalDateTime crtime;

   public boolean ifContainsAccPayDetail() {
      if (!PayChannelEnum.ACC.getKey().equals(this.payChannel)) {
         return false;
      } else if (this.amount.compareTo(BigDecimal.ZERO) == 0) {
         return false;
      } else {
         return this.walletAmount != null && this.walletAmount.compareTo(BigDecimal.ZERO) > 0 || this.subsidyAmount != null && this.subsidyAmount.compareTo(BigDecimal.ZERO) > 0 || this.redEnvelopeAmount != null && this.redEnvelopeAmount.compareTo(BigDecimal.ZERO) > 0;
      }
   }

   public static String[] logFields() {
      return new String[]{"amountDetailId", "orderId", "amountType", "payType", "payChannel"};
   }

   public Long getAmountDetailId() {
      return this.amountDetailId;
   }

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

   public Long getTradeChannelId() {
      return this.tradeChannelId;
   }

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

   public Long getOrderRefundId() {
      return this.orderRefundId;
   }

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

   public BigDecimal getWalletAmount() {
      return this.walletAmount;
   }

   public BigDecimal getSubsidyAmount() {
      return this.subsidyAmount;
   }

   public BigDecimal getRedEnvelopeAmount() {
      return this.redEnvelopeAmount;
   }

   public Integer getAmountDetailType() {
      return this.amountDetailType;
   }

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

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

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

   public LocalDateTime getCrtime() {
      return this.crtime;
   }

   public void setAmountDetailId(final Long amountDetailId) {
      this.amountDetailId = amountDetailId;
   }

   @JsonFormat(
      pattern = "yyyy-MM-dd"
   )
   public void setOrderDate(final LocalDate orderDate) {
      this.orderDate = orderDate;
   }

   public void setTradeChannelId(final Long tradeChannelId) {
      this.tradeChannelId = tradeChannelId;
   }

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

   public void setOrderRefundId(final Long orderRefundId) {
      this.orderRefundId = orderRefundId;
   }

   public void setAmount(final BigDecimal amount) {
      this.amount = amount;
   }

   public void setWalletAmount(final BigDecimal walletAmount) {
      this.walletAmount = walletAmount;
   }

   public void setSubsidyAmount(final BigDecimal subsidyAmount) {
      this.subsidyAmount = subsidyAmount;
   }

   public void setRedEnvelopeAmount(final BigDecimal redEnvelopeAmount) {
      this.redEnvelopeAmount = redEnvelopeAmount;
   }

   public void setAmountDetailType(final Integer amountDetailType) {
      this.amountDetailType = amountDetailType;
   }

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

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

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

   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   public void setCrtime(final LocalDateTime crtime) {
      this.crtime = crtime;
   }

}
