package de.kif.common.model

import de.kif.common.SearchElement
import kotlinx.serialization.Serializable

@Serializable
data class Track(
    override val id: Long? = null,
    val name: String = "",
    val color: Color = Color.WHITE,
    override val createdAt: Long = 0,
    override val updateAt: Long = 0
) : Model {

    override fun createSearch() = SearchElement(
        mapOf(
            "name" to name
        )
    )

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other == null || this::class != other::class) return false

        other as Track

        if (id != other.id) return false
        if (name != other.name) return false
        if (color != other.color) return false

        return true
    }

    fun equalsIgnoreId(other: Track): Boolean = copy(id = null) == other.copy(id = null)

    override fun hashCode(): Int {
        var result = id?.hashCode() ?: 0
        result = 31 * result + name.hashCode()
        result = 31 * result + color.hashCode()
        return result
    }
}
