package de.assecutor.votianlt.messaging.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * Receipt returned when a message is submitted for delivery.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeliveryReceipt {

    /**
     * Unique message identifier
     */
    private String messageId;

    /**
     * Topic where message was sent
     */
    private String topic;

    /**
     * When the message was submitted
     */
    private LocalDateTime submittedAt;

    /**
     * Initial delivery status
     */
    private DeliveryStatus status;

    /**
     * When the message will expire
     */
    private LocalDateTime expiresAt;

    /**
     * Create a receipt for a successfully submitted message
     */
    public static DeliveryReceipt submitted(String messageId, String topic, LocalDateTime expiresAt) {
        return new DeliveryReceipt(
            messageId,
            topic,
            LocalDateTime.now(),
            DeliveryStatus.PENDING,
            expiresAt
        );
    }

    /**
     * Create a receipt for a failed submission
     */
    public static DeliveryReceipt failed(String messageId, String topic) {
        return new DeliveryReceipt(
            messageId,
            topic,
            LocalDateTime.now(),
            DeliveryStatus.FAILED,
            null
        );
    }
}

