package com.zyzf.coffeepreorder.database.model

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

@Entity(tableName = "coffee")
data class Coffee(
    @PrimaryKey(autoGenerate = true)
    val uid: Int = 0,
    @ColumnInfo(name = "name")
    var name: String,
    @ColumnInfo(name = "cost")
    var cost: Double,
    @ColumnInfo(name = "ingredients")
    var ingredients: String
) {
    @Ignore
    constructor(
        name: String,
        cost: Double,
        ingredients: String
    ) : this(0, name, cost, ingredients)

    companion object {
        fun getCoffee(index: Int = 0): Coffee {
            return Coffee(
                index,
                "",
                0.0,
                ""
            )
        }
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Coffee
        if (uid != other.uid) return false
        if (name != other.name) return false
        if (cost != other.cost) return false
        return ingredients == other.ingredients
    }

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