package com.red.circle.game.fruit.infrastructure.websocket.message;

import com.red.circle.tool.core.date.DateUtils;
import com.red.circle.tool.core.json.JacksonUtils;
import com.red.circle.tool.core.text.StringUtils;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 消息体.
 *
 * @author pengliang on 2021/7/19
 */
@Data
@Accessors(chain = true)
public class SocketMessageBody implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 消息内容
   */
  private String content;

  /**
   * 广播转发的目标地址（告知 STOMP 代理转发到哪个地方）
   */
  private String destination;

  /**
   * 目标用户.
   */
  private String targetUser;

  /**
   * 消息id.
   */
  private String msgId;

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

  public static SocketMessageBody createMessage(String destination, Object body) {
    return new SocketMessageBody()
        .setMsgId(StringUtils.getUUID())
        .setDestination(destination)
        .setContent(JacksonUtils.toJson(body))
        .setCreateTime(DateUtils.now());
  }

}
