package com.example.myapplication.database.room.model.bike

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey

@Entity(tableName = "bikes")
data class Bike(
    @PrimaryKey(autoGenerate = true)
    val uid: Int = 0,
    val name: String,
    val description: String,
    @ColumnInfo(typeAffinity = ColumnInfo.BLOB)
    val image: ByteArray?
) {
    @Ignore
    constructor(
        name: String,
        description: String,
        image: ByteArray?
    ) : this(0, name, description, image)

    companion object {
        fun getBike(index: Int = 0): Bike {
            return Bike(
                index,
                "name",
                "desc",
                byteArrayOf()
            )
        }
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Bike
        if (uid != other.uid) return false
        if (name != other.name) return false
        if (description != other.description) return false
        return image.contentEquals(other.image)
    }

    override fun hashCode(): Int {
        var result = uid
        result = 31 * result + name.hashCode()
        result = 31 * result + description.hashCode()
        return result
    }
}

