package com.example.myapplication.database.entities

import android.graphics.Bitmap
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey

@Entity(
    tableName = "products",
    foreignKeys = [
        ForeignKey(
            entity = Category::class,
            parentColumns = ["id"],
            childColumns = ["category_id"],
            onDelete = ForeignKey.RESTRICT,
            onUpdate = ForeignKey.RESTRICT
        )
    ]
)
data class Product(
    @PrimaryKey(autoGenerate = true)
    var productId: Int?,
    @ColumnInfo(name="name")
    val name: String,
    @ColumnInfo(name="info")
    val info: String,
    @ColumnInfo(name="price")
    val price: Double,
    @ColumnInfo(name="img")
    val img: Bitmap,
    @ColumnInfo(name="category_id")
    val categoryId: Int
){
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Product
        if (productId != other.productId) return false
        return true
    }
    override fun hashCode(): Int {
        return productId ?: -1
    }

}
