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.SimpleDateFormat import java.util.Date import java.util.Locale enum class OrderStatus(val displayName: String, val colorHex: Long) { PREPARING("Hazırlanıyor", 0xFFE5A93C), SHIPPED("Kargoya Verildi", 0xFF2A85FF), DELIVERED("Teslim Edildi", 0xFF20B26C), CANCELLED("İptal Edildi", 0xFFE53935) } enum class PaymentStatus(val displayName: String) { PENDING("Ödeme Bekleniyor"), COMPLETED("Ödendi"), FAILED("Başarısız") } @IgnoreExtraProperties data class OrderItem( val productId: String = "", val title: String = "", val imageUrl: String = "", val price: Double = 0.0, val quantity: Long = 1L ) { val totalPrice: Double get() = price * quantity } @IgnoreExtraProperties data class Order( @DocumentId val id: String = "", val orderNumber: String = "", val userId: String = "", val userEmail: String = "", val items: List = emptyList(), val deliveryAddress: Address = Address(), val subtotal: Double = 0.0, val discount: Double = 0.0, val shippingCost: Double = 0.0, val totalAmount: Double = 0.0, val orderStatus: String = OrderStatus.PREPARING.name, val paymentStatus: String = PaymentStatus.PENDING.name, val paymentMethod: String = "Havale / EFT & Kapıda Ödeme", val cargoCompany: String = "", val trackingNumber: String = "", val adminNotes: String = "", @ServerTimestamp val createdAt: Timestamp? = null, @ServerTimestamp val updatedAt: Timestamp? = null ) { val statusEnum: OrderStatus get() = try { OrderStatus.valueOf(orderStatus) } catch (_: Exception) { OrderStatus.PREPARING } val paymentStatusEnum: PaymentStatus get() = try { PaymentStatus.valueOf(paymentStatus) } catch (_: Exception) { PaymentStatus.PENDING } val formattedDate: String get() = createdAt?.toDate()?.let { SimpleDateFormat("dd.MM.yyyy HH:mm", Locale("tr", "TR")).format(it) } ?: SimpleDateFormat("dd.MM.yyyy", Locale("tr", "TR")).format(Date()) val formattedTotal: String get() = Product.formatCurrency(totalAmount) }