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

import com.red.circle.common.business.core.enums.OpUserType;
import com.red.circle.common.business.core.enums.ReceiptType;
import com.red.circle.tool.core.tuple.PennyAmount;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 消费金币收据.
 *
 * @author pengliang on 2021/8/20
 */
@Data
@Accessors(chain = true)
public class WalletReceipt implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 请求ID,用户幂等校验.
   */
  private String reqTraceId;

  /**
   * 单据类型.
   */
  @NotNull(message = "receiptType required.")
  private ReceiptType receiptType;

  /**
   * 用户id.
   */
  @NotNull(message = "userId required.")
  private Long userId;

  /**
   * 归属系统.
   */
  @NotBlank(message = "sysOrigin required.")
  private String sysOrigin;

  /**
   * 事件类型.
   */
  @NotBlank(message = "eventType required.")
  private String eventType;

  /**
   * 事件描述.
   */
  @NotBlank(message = "eventDesc required.")
  private String eventDesc;

  /**
   * 事件id(订单，关联信息).
   */
  @NotBlank(message = "eventId required.")
  private String eventId;

  /**
   * 备注.
   */
  private String remark;

  /**
   * 操作用户类型(0.app用户， 1.后台管理用户).
   */
  private OpUserType opUserType;

  /**
   * 金币数量.
   */
  @NotNull(message = "amount required.")
  private PennyAmount amount;

  /**
   * 创建时间.
   */
  @NotNull(message = "createTime required.")
  private Date createTime;

  /**
   * true: 关闭流水同步， false&null: 开启
   */
  private Boolean closeDelayAsset;

  /**
   * 操作用户.
   */
  private Long opUserId;

  public int receiptTypeVal() {
    return receiptType.getType();
  }

  public boolean checkTypeIncome() {
    return Objects.equals(receiptType, ReceiptType.INCOME);
  }

  public boolean checkExpenditure() {
    return Objects.equals(receiptType, ReceiptType.EXPENDITURE);
  }

}
