package dev.kaizen.app.db

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import dev.kaizen.app.net.Attachment
import dev.kaizen.app.net.SearchSource

@Entity(tableName = "conversations")
data class ConversationEntity(
    @PrimaryKey val id: String,
    val title: String,
    val locked: Boolean,
    val pinned: Boolean,
    val updatedAt: String?,
    val cachedAt: Long,
    val titleGenerated: Boolean = false,
)

@Entity(
    tableName = "messages",
    foreignKeys = [ForeignKey(
        entity = ConversationEntity::class,
        parentColumns = ["id"],
        childColumns = ["conversationId"],
        onDelete = ForeignKey.CASCADE,
    )],
    indices = [Index("conversationId")],
)
data class MessageEntity(
    @PrimaryKey val id: String,
    val conversationId: String,
    val role: String,
    val content: String,
    val attachments: List<Attachment>,
    val sortOrder: Int,
    val reasoning: String? = null,
    val sources: List<SearchSource> = emptyList(),
    val ttsUrl: String? = null,
    val ttsVoice: String? = null,
)
