package com.aiwazian.messenger.data

import androidx.annotation.Keep
import kotlinx.serialization.Serializable
import com.google.gson.annotations.SerializedName

@Keep
@Serializable
data class Message(
    @Keep var id: Int = 0,
    @Keep val senderId: Long = 0,
    @Keep val chatId: Long = 0,
    @Keep val text: String? = null,
    @Keep val sendTime: Long = 0,
    @Keep var isRead: Boolean = false,
    @Keep @SerializedName(value = "files", alternate = ["attachments"])
    val attachments: Array<Attachment> = emptyArray(),
    @Keep val kanbanBoardId: Int? = null,
    @Keep val kanbanTaskId: Int? = null,
    @Keep val kanbanBoard: KanbanBoard? = null,
    @Keep val kanbanTask: KanbanTask? = null
) {
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        
        other as Message
        
        if (id != other.id) return false
        if (senderId != other.senderId) return false
        if (chatId != other.chatId) return false
        if (sendTime != other.sendTime) return false
        if (isRead != other.isRead) return false
        if (text != other.text) return false
        if (!attachments.contentEquals(other.attachments)) return false
        if (kanbanBoardId != other.kanbanBoardId) return false
        if (kanbanTaskId != other.kanbanTaskId) return false
        if (kanbanBoard != other.kanbanBoard) return false
        if (kanbanTask != other.kanbanTask) return false
        
        return true
    }
    
    override fun hashCode(): Int {
        var result = id
        result = 31 * result + senderId.hashCode()
        result = 31 * result + chatId.hashCode()
        result = 31 * result + sendTime.hashCode()
        result = 31 * result + isRead.hashCode()
        result = 31 * result + (text?.hashCode() ?: 0)
        result = 31 * result + attachments.contentHashCode()
        result = 31 * result + (kanbanBoardId ?: 0)
        result = 31 * result + (kanbanTaskId ?: 0)
        result = 31 * result + (kanbanBoard?.hashCode() ?: 0)
        result = 31 * result + (kanbanTask?.hashCode() ?: 0)
        return result
    }
}
