package de.assecutor.votianlt.messaging.model;

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

import java.time.LocalDateTime;

/**
 * Acknowledgment message sent by clients to confirm message receipt/processing.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AcknowledgmentMessage {

    /**
     * ID of the message being acknowledged
     */
    private String messageId;

    /**
     * Status of the acknowledgment
     */
    private AckStatus status;

    /**
     * Timestamp when the acknowledgment was created
     */
    private LocalDateTime timestamp;

    /**
     * ID of the client sending the acknowledgment
     */
    private String clientId;

    /**
     * Optional error message if status is FAILED
     */
    private String errorMessage;

    /**
     * Constructor for successful acknowledgment
     */
    public AcknowledgmentMessage(String messageId, AckStatus status, String clientId) {
        this.messageId = messageId;
        this.status = status;
        this.timestamp = LocalDateTime.now();
        this.clientId = clientId;
    }

    /**
     * Constructor for failed acknowledgment with error message
     */
    public AcknowledgmentMessage(String messageId, String clientId, String errorMessage) {
        this.messageId = messageId;
        this.status = AckStatus.FAILED;
        this.timestamp = LocalDateTime.now();
        this.clientId = clientId;
        this.errorMessage = errorMessage;
    }
}

