package com.laseroptek.raman.data.source.db.model

import androidx.compose.runtime.Immutable
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey

@Entity(
    tableName = "serial_log",
    indices = [
        Index("id", unique = true)
    ]
)
@Immutable
data class SerialLog(
    @PrimaryKey(autoGenerate = true)
    val id: Long = 0, // Optional: auto-generated primary key
    val ts: Long = 0,
    val cmd: Int = 0,
    val tx: Boolean = false,
    val w: Boolean = false,
    val data: ByteArray = emptyList<Byte>().toByteArray(), // Room can handle ByteArray
    val desc: String = ""
) {
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as SerialLog

        if (id != other.id) return false
        if (ts != other.ts) return false
        if (cmd != other.cmd) return false
        if (tx != other.tx) return false
        if (w != other.w) return false
        if (!data.contentEquals(other.data)) return false
        if (desc != other.desc) return false

        return true
    }

    override fun hashCode(): Int {
        var result = id.hashCode()
        result = 31 * result + ts.hashCode()
        result = 31 * result + cmd
        result = 31 * result + tx.hashCode()
        result = 31 * result + w.hashCode()
        result = 31 * result + data.contentHashCode()
        result = 31 * result + desc.hashCode()
        return result
    }
}
