package de.assecutor.votianlt.dto;

import de.assecutor.votianlt.model.Message;
import de.assecutor.votianlt.model.MessageContentType;
import de.assecutor.votianlt.model.MessageOrigin;
import de.assecutor.votianlt.model.MessageType;
import java.time.LocalDateTime;

/**
 * Outbound chat message payload published to subscribers. The receiver is
 * implicit from the WebSocket session (/client/message)
 */
public record ChatMessageOutboundPayload(String messageId, String content, MessageContentType contentType,
        MessageOrigin origin, MessageType messageType, LocalDateTime createdAt, String jobId, String jobNumber,
        boolean read) {

    public static ChatMessageOutboundPayload fromMessage(Message message) {
        return new ChatMessageOutboundPayload(message.getIdAsString(), message.getContent(), message.getContentType(),
                message.getOrigin(), message.getMessageType(), message.getCreatedAt(), message.getJobIdAsString(),
                message.getJobNumber(), message.isRead());
    }
}
