package com.example.notesai.data.model

import kotlinx.serialization.Serializable
import java.util.UUID

@Serializable
data class ChatHistory(
    val id: String = UUID.randomUUID().toString(),
    val categoryId: String?, // null berarti "Semua Kategori"
    val categoryName: String, // Untuk display
    val messages: List<SerializableChatMessage>,
    val lastMessagePreview: String, // Preview pesan terakhir
    val customTitle: String? = null, // Custom title yang di-edit user (support markdown)
    val timestamp: Long = System.currentTimeMillis(),
    val isDeleted: Boolean = false
)

@Serializable
data class SerializableChatMessage(
    val id: String,
    val message: String,
    val isUser: Boolean,
    val timestamp: Long
)

// Extension function untuk convert ChatMessage ke SerializableChatMessage
fun ChatMessage.toSerializable() = SerializableChatMessage(
    id = id,
    message = message,
    isUser = isUser,
    timestamp = timestamp
)

// Extension function untuk convert SerializableChatMessage ke ChatMessage
fun SerializableChatMessage.toChatMessage() = ChatMessage(
    id = id,
    message = message,
    isUser = isUser,
    timestamp = timestamp
)