package com.red.circle.mq.business.model.event.wallet;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
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 java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import lombok.Data;

/**
 * 钱包资产事件.
 *
 * @author pengliang on 2023/7/2
 */
@Data
public class WalletReceiptSyncEvent implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 资产记录id.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long assetRecordId;

  /**
   * 单据类型.
   */
  private ReceiptType receiptType;

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

  /**
   * 归属系统.
   */
  private String sysOrigin;

  /**
   * 事件类型.
   */
  private String eventType;

  /**
   * 事件描述.
   */
  private String eventDesc;

  /**
   * 事件id(订单，关联信息).
   */
  private String eventId;

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

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

  /**
   * 业务类型.
   */
  private Integer bizType;

  /**
   * 金币数量.
   */
  private PennyAmount amount;

  /**
   * 余额.
   */
  private PennyAmount balance;

  /**
   * 创建时间.
   */
  private Date createTime;

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

  /**
   * 操作用户id.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long opUserId;


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

  public int opUserTypeVal() {
    return opUserType.getType();
  }

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

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

}
