package com.red.circle.live.infra.log;

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 com.red.circle.tool.core.json.JacksonUtils;
import java.util.Objects;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author pengliang on 2024/1/18
 */
@Data
@Accessors(chain = true)
public class LiveHeartbeatLog implements ToClsLog {

  public static final String TOPIC = "c6b42616-5cd7-465e-a40d-8f7520b4c2de";
  /**
   * 记录id.
   */
  private String id;

  /**
   * 环境.
   */
  private String env;

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

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

  /**
   * 房间会话ID.
   */
  private String sessionId;

  /**
   * 参数体.
   */
  private Object body;

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

  @Override
  public ClsLogItem toLog() {
    long cTime = Objects.isNull(createTime) ? DateUtils.now().getTime() : createTime;
    return ClsLogItem.create(cTime)
        .put("id", id)
        .put("sysOrigin", sysOrigin)
        .put("userId", Objects.toString(userId))
        .put("sessionId", sessionId)
        .put("body", JacksonUtils.toJson(body))
        .put("createTime", Objects.toString(cTime));
  }
}
