package com.red.circle.wallet.infra.tool;

import com.red.circle.component.tencent.cls.request.ClsLogItem;
import com.red.circle.component.tencent.cls.service.ToClsLog;
import com.red.circle.tool.core.date.DateUtils;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * <p>
 * 用户金币资产流水.
 * </p>
 *
 * @author pengliang on 2023/06/30
 */
@Data
@Accessors(chain = true)
public class WalletGoldAssetRecordLog implements ToClsLog, Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 流水记录ID.
   */
  private Long id;

  /**
   * 系统来源.
   */
  private String sysOrigin;

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

  /**
   * 金额.
   */
  private Long pennyAmount;

  /**
   * 当前余额.
   */
  private Long pennyBalance;

  /**
   * 类型0.收入 1.消耗.
   */
  private Integer type;

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

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

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

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

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

  /**
   * 创建用户.
   */
  private Long createUser;


  @Override
  public ClsLogItem toLog() {
    long cTime = Objects.isNull(createTime) ? DateUtils.now().getTime() : createTime.getTime();
    return ClsLogItem.create(cTime)
        .put("id", Objects.toString(id))
        .put("sysOrigin", sysOrigin)
        .put("userId", Objects.toString(userId))
        .put("pennyAmount", Objects.toString(pennyAmount))
        .put("pennyBalance", Objects.toString(pennyBalance))
        .put("type", Objects.toString(type))
        .put("eventType", eventType)
        .put("eventDesc", eventDesc)
        .put("eventId", eventId)
        .put("opUserType", Objects.toString(opUserType))
        .put("createTime", Objects.toString(cTime))
        .put("createUser", Objects.toString(createUser));
  }

}
