package com.fabledsword.minstrel.cache.db.entities

import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant

/**
 * Single-row snapshot of the `/api/me/history` response, stored as the
 * raw wire JSON so the History tab paints instantly from disk on cold
 * open and survives connectivity loss. Mirrors the Flutter Drift
 * `CachedHistorySnapshot` table (id defaults to 1; one row total).
 *
 * Cache-first + SWR: the tab observes this row and a background refresh
 * overwrites it, so the freshest plays land without a blocking spinner.
 */
@Entity(tableName = "cached_history_snapshot")
data class CachedHistorySnapshotEntity(
    @PrimaryKey val id: Int = SINGLETON_ID,
    val json: String,
    val updatedAt: Instant = Clock.System.now(),
) {
    companion object {
        const val SINGLETON_ID = 1
    }
}
