package space.nstart.pcp.pcp_types_lib.message

import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonAlias
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import space.nstart.pcp.pcp_types_lib.utils.json.LocalDateTimeTimeZoneSerializer
import space.nstart.pcp.pcp_types_lib.utils.UtcDateTimes
import java.time.LocalDateTime
import java.util.*


class KafkaMessage<out T> (
    val type: KafkaEvent,
    val data: T,
    @param:JsonAlias("trace_id", "traceid")
    val traceId: String = UUID.randomUUID().toString(),
    @param:JsonAlias("correlationid")
    val correlationId: String = UUID.randomUUID().toString(),
    val group: String? = null,
) {
    val id = UUID.randomUUID().toString()
    var source = "Example"

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS[xxx]")
    @JsonSerialize(using = LocalDateTimeTimeZoneSerializer::class)
    val time: LocalDateTime = UtcDateTimes.now()

    val dataContentType = "application/json"
    val specVersion = "1.0"
}
