package ru.forbion.f7cloud.feature.talk

data class TalkMessage(
    val id: Long,
    val actorDisplayName: String,
    val actorId: String = "",
    val text: String,
    val timestamp: Long,
    val messageType: String = "comment",
    val status: Status = Status.SENT,
    val replyToId: Long? = null,
    val reactions: Map<String, Int> = emptyMap(),
    val messageParameters: Map<String, TalkMessageParameter> = emptyMap(),
    val attachmentFileId: String? = null,
    val attachmentFileName: String? = null,
    val attachmentMimeType: String? = null,
    val attachmentLink: String? = null,
) {
    enum class Status {
        SENT,
        SENDING,
        FAILED,
    }

    val isSystemMessage: Boolean get() = messageType != "comment"
    val isVoiceMessage: Boolean get() = messageType == "voice-message"
    val displayText: String
        get() = if (isSystemMessage) formatSystemMessage(text, messageParameters, actorDisplayName) else text
    val hasImageAttachment: Boolean
        get() = attachmentMimeType?.startsWith("image/") == true ||
            attachmentFileName.orEmpty().matches(Regex("""(?i)\.(jpg|jpeg|png|gif|webp|bmp)$"""))
}
