package com.red.circle.wallet.domain.wallet;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.red.circle.common.business.core.enums.ReceiptType;
import com.red.circle.tool.core.num.ArithmeticUtils;
import jakarta.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * <p>
 * 用户积分来源
 * </p>
 *
 * @author pengliang
 * @since 2020-05-13
 */
@Data
@Accessors(chain = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public class CommissionDiamondReceipt implements Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * 消费id.
   */
  @NotNull
  @JsonSerialize(using = ToStringSerializer.class)
  private String consumeId;

  /**
   * 用户id
   */
  @NotNull
  @JsonSerialize(using = ToStringSerializer.class)
  private Long userId;

  /**
   * 来源用户
   */
  @NotNull
  private Long originUserId;

  /**
   * 来源
   */
  @NotNull
  private String origin;

  /**
   * 积分数量
   */
  @NotNull
  private BigDecimal amount;

  /**
   * 类型0.收入 1.支出
   */
  @NotNull
  private ReceiptType type;

  /**
   * 创建时间
   */
  @NotNull
  private Timestamp createTime;

  public boolean checkAmountIsLteZero() {
    return ArithmeticUtils.lteZero(amount);
  }

  public String getChangeBalanceConsumeKey() {
    return "CHANGE_COMMISSION_DIAMOND_BALANCE:" + getConsumeId();
  }
}
