package com.yami.shop.bean.dto.hb;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 基础消息对象
 *
 * @author mr wang
 * @version 1.0.0
 * @since 2025-09-01
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseMessage<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 消息ID
     */
    private String messageId;

    /**
     * 消息类型
     */
    private String messageType;

    /**
     * 业务键
     */
    private String businessKey;

    /**
     * 时间戳
     */
    private LocalDateTime timestamp;

    /**
     * 来源系统
     */
    private String sourceSystem;

    /**
     * 消息数据
     */
    private T data;

    /**
     * 创建基础消息
     *
     * @param messageType 消息类型
     * @param businessKey 业务键
     * @param data        消息数据
     * @param <T>         数据类型
     * @return 基础消息对象
     */
    public static <T> BaseMessage<T> create(String messageType, String businessKey, T data) {
        return BaseMessage.<T>builder()
                .messageId(java.util.UUID.randomUUID().toString())
                .messageType(messageType)
                .businessKey(businessKey)
                .timestamp(LocalDateTime.now())
                .sourceSystem("zs-core-service")
                .data(data)
                .build();
    }
}
