package com.pablotj.ia.chat.boot.persistence;

import com.pablotj.ia.chat.boot.domain.model.ChatIdentity;
import com.pablotj.ia.chat.boot.domain.model.ChatMessage;

public class ChatMessageMapper {

    private ChatMessageMapper() throws IllegalAccessException {
        throw new IllegalAccessException("Private access to ChatMessageMapper");
    }

    public static ChatMessageEntity toEntity(String chatId, ChatMessage message) {
        ChatMessageEntity entity = new ChatMessageEntity();
        entity.setSessionId(chatId);
        entity.setRole(message.role());
        entity.setText(message.text());
        entity.setDate(message.date());
        return entity;
    }

    public static ChatMessage toDomain(ChatMessageEntity entity) {
        return new ChatMessage(entity.getSessionId(), entity.getRole(), entity.getText(), entity.getDate());
    }

    public static ChatIdentity toEntityId(ChatMessageEntity m) {
        return new ChatIdentity(m.getSessionId(), m.getText().length() > 35 ? m.getText().substring(0, 35).concat("...") : m.getText());
    }
}