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

import com.red.circle.common.business.core.enums.ReceiptType;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.tool.core.num.ArithmeticUtils;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Objects;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 消费游戏券收据.
 *
 * @author pengshigang on 2021/12/21
 */
@Data
@Accessors(chain = true)
public class GameCouponReceipt implements Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * 消费id.
   */
  @NotNull
  private Long consumeId;

  /**
   * 追踪id.
   */
  @NotNull
  private Long trackId;

  /**
   * 单据类型.
   */
  @NotNull
  private ReceiptType type;

  /**
   * 用户id.
   */
  @NotNull
  private Long userId;

  /**
   * 归属系统.
   */
  @NotNull
  private SysOriginPlatformEnum sysOrigin;

  /**
   * 游戏券来源.
   */
  @NotNull
  private String origin;

  /**
   * 来源描述.
   */
  @NotBlank
  private String originDesc;

  /**
   * 游戏券数量.
   */
  @NotNull
  private BigDecimal amount;

  public boolean isTypeIncome() {
    return Objects.equals(type, ReceiptType.INCOME);
  }

  public boolean isExpenditure() {
    return Objects.equals(type, ReceiptType.EXPENDITURE);
  }

  public String getSysOriginName() {
    return getSysOrigin().name();
  }

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

  public String getChangeBalanceConsumeKey() {
    return "CHANGE_GAME_COUPON_BALANCE:" + consumeId;
  }
}
