package leigh.minecraft.link.event;

import leigh.eo.EO;
import leigh.minecraft.link.sdk.schema.v1.ChatMessageElementDAO;

import java.util.UUID;

/**
 * This mesage represents a chat message which originated on a Bukkit server.
 *
 * @author Alex Leigh
 */
public class ChatMessage {
    private final UUID playerId;
    private final String playerName;
    private String message;

    public ChatMessage(UUID playerId, String playerName, String message) {
        this.playerId = playerId;
        this.playerName = playerName;
        this.message = message;
    }

    /**
     * Convert this chat message into {@link EO} form and return it. The message will be created in accordance
     * with the {@link ChatMessageElementDAO} schema.
     */
    public EO getAsEO() {
        EO msg = ChatMessageElementDAO.create();
        ChatMessageElementDAO.setSrcId(msg, playerId);
        ChatMessageElementDAO.setSrcName(msg, playerName);
        ChatMessageElementDAO.setMsg(msg, message);
        return msg;
    }
}
