package lu.rewardflow.terminal.data.db.entity

import androidx.room.Entity
import androidx.room.PrimaryKey

/**
 * Offline transaction queue.
 *
 * When the device is offline, transactions (stamp, points, enrollment)
 * are stored here and synced via WorkManager when connectivity returns.
 */
@Entity(tableName = "pending_transactions")
data class PendingTransaction(
    @PrimaryKey(autoGenerate = true) val id: Long = 0,

    /** Type: "stamp", "points_earn", "enroll" */
    val type: String,

    /** JSON payload matching the API request body */
    val requestJson: String,

    /** Staff PIN ID who initiated the transaction */
    val staffPinId: Int,

    /** When the transaction was created locally */
    val createdAt: Long = System.currentTimeMillis(),

    /** Number of sync attempts */
    val retryCount: Int = 0,

    /** Last sync error (null if not yet attempted) */
    val lastError: String? = null,

    /** "pending", "syncing", "synced", "failed" */
    val status: String = "pending",
)
