package com.bonus.core.pay.common.model;

import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.format.annotation.DateTimeFormat;

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

@TableName("trade_channel")
public class TradeChannel {
   @TableId
   private Long tradeChannelId;
   private Long tradeId;
   private BigDecimal amount;
   private BigDecimal refundAmount;
   private Integer tradeState;
   private Integer payType;
   private Integer payChannel;
   private String tradeResult;
   private String outTradeNo;
   private LocalDateTime tradeTime;
   private JsonNode param;
   private JsonNode extParam;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   private LocalDateTime createTime;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   private LocalDateTime updateTime;

   public BigDecimal calcRefundableAmount() {
      return NumberUtil.sub(this.amount, this.refundAmount);
   }

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

   public Long getTradeId() {
      return this.tradeId;
   }

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

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

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

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

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

   public String getTradeResult() {
      return this.tradeResult;
   }

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

   public LocalDateTime getTradeTime() {
      return this.tradeTime;
   }

   public JsonNode getParam() {
      return this.param;
   }

   public JsonNode getExtParam() {
      return this.extParam;
   }

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

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

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

   public void setTradeId(final Long tradeId) {
      this.tradeId = tradeId;
   }

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

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

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

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

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

   public void setTradeResult(final String tradeResult) {
      this.tradeResult = tradeResult;
   }

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

   public void setTradeTime(final LocalDateTime tradeTime) {
      this.tradeTime = tradeTime;
   }

   public void setParam(final JsonNode param) {
      this.param = param;
   }

   public void setExtParam(final JsonNode extParam) {
      this.extParam = extParam;
   }

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

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