package com.ycwl.basic.integration.kafka.dto;

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

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class KafkaMessage<T> {

    private String messageId;
    private String topic;
    private String eventType;
    private T payload;
    
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime timestamp;
    
    private String source;
    private String version;

    public static <T> KafkaMessage<T> of(String topic, String eventType, T payload) {
        return KafkaMessage.<T>builder()
                .topic(topic)
                .eventType(eventType)
                .payload(payload)
                .timestamp(LocalDateTime.now())
                .source("liuying-microservice")
                .version("1.0")
                .build();
    }
}