package com.lingniu.ingest.api.consumer;

import java.time.Instant;

public record EnvelopeDeadLetterRecord(
        String service,
        String topic,
        int partition,
        long offset,
        String key,
        EnvelopeIngestResult.Status status,
        String eventId,
        String vin,
        String message,
        byte[] payload,
        Instant createdAt
) {
    public EnvelopeDeadLetterRecord {
        service = service == null ? "" : service;
        topic = topic == null ? "" : topic;
        key = key == null ? "" : key;
        if (status == null) {
            throw new IllegalArgumentException("status must not be null");
        }
        eventId = eventId == null ? "" : eventId;
        vin = vin == null ? "" : vin;
        message = message == null ? "" : message;
        payload = payload == null ? new byte[0] : payload.clone();
        createdAt = createdAt == null ? Instant.now() : createdAt;
    }

    @Override
    public byte[] payload() {
        return payload.clone();
    }
}
