package com.tashow.cloud.app.mq.message;
import lombok.Data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public class BuriedMessages implements Serializable {

    // 消息队列配置
    public static final String QUEUE = "BURIED_POINT_QUEUE";
    public static final String EXCHANGE = "BURIED_POINT_EXCHANGE";
    public static final String ROUTING_KEY = "BURIED_POINT_ROUTING_KEY";
    public static final String DEAD_LETTER_EXCHANGE = "DEAD_LETTER_EXCHANGE";
    public static final String DEAD_LETTER_ROUTING_KEY = "DEAD_LETTER_ROUTING";
    public static final String DEAD_LETTER_QUEUE = "DEAD_LETTER_QUEUE";

    // 状态码定义
    public static final Integer STATUS_INIT = 10;       // 初始状态
    public static final Integer STATUS_PROCESSING = 20; // 处理中
    public static final Integer STATUS_SUCCESS = 30;    // 处理成功
    public static final Integer STATUS_WARNING = 40;    // 处理警告
    public static final Integer STATUS_ERROR = 50;      // 处理错误

    // 通用字段
    private Integer id;           // 事件唯一ID
    private Long eventTime;       // 事件时间戳
    private String service;       // 服务名称
    private String method;        // 方法/接口
    private String userId;        // 用户标识
    private String sessionId;     // 会话标识
    private String clientIp;      // 客户端IP
    private String serverIp;      // 服务器IP
    
    // 添加埋点特定字段
    private String eventType;     // 事件类型: PAGE_VIEW, API_CALL, BUTTON_CLICK 等
    private String pagePath;      // 页面路径/功能模块
    private String elementId;     // 元素标识
    private Long duration;        // 操作时长(毫秒)
    private String deviceInfo;    // 设备信息
    private String userAgent;     // 用户代理信息
    private Integer statusCode;   // 响应状态码
    private String errorMessage;  // 错误信息
    
    // 扩展字段，用于存储特定事件的额外数据
    private Map<String, Object> extraData = new HashMap<>();

    /**
     * 快速创建消息的便捷方法
     */
    public static BuriedMessages create(String userId, String eventType, String pagePath) {
        BuriedMessages msg = new BuriedMessages();
        msg.setUserId(userId);
        msg.setEventType(eventType);
        msg.setPagePath(pagePath);
        msg.setEventTime(System.currentTimeMillis());
        msg.setStatusCode(STATUS_INIT); // 默认初始状态
        return msg;
    }
    
    /**
     * 添加扩展数据
     */
    public BuriedMessages addExtraData(String key, Object value) {
        if (this.extraData == null) {
            this.extraData = new HashMap<>();
        }
        this.extraData.put(key, value);
        return this;
    }
}
