package com.aistudio.bonjuteri.jwlry.model import com.google.firebase.Timestamp import com.google.firebase.firestore.DocumentId import com.google.firebase.firestore.IgnoreExtraProperties import com.google.firebase.firestore.ServerTimestamp import java.text.NumberFormat import java.util.Locale @IgnoreExtraProperties data class Product( @DocumentId val id: String = "", val title: String = "", val description: String = "", val sku: String = "", val category: String = "", val price: Double = 0.0, val oldPrice: Double? = null, val stock: Long = 0L, val imageUrl: String = "", val isActive: Boolean = true, val isNew: Boolean = false, val isBestSeller: Boolean = false, val isFeatured: Boolean = false, @ServerTimestamp val createdAt: Timestamp? = null, @ServerTimestamp val updatedAt: Timestamp? = null ) { val formattedPrice: String get() = formatCurrency(price) val formattedOldPrice: String? get() = oldPrice?.let { formatCurrency(it) } val hasDiscount: Boolean get() = oldPrice != null && oldPrice > price val discountPercent: Int get() = if (hasDiscount && oldPrice != null && oldPrice > 0) { (((oldPrice - price) / oldPrice) * 100).toInt() } else { 0 } val isInStock: Boolean get() = stock > 0L companion object { fun formatCurrency(amount: Double): String { val format = NumberFormat.getCurrencyInstance(Locale("tr", "TR")) return format.format(amount) } } }