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 last playback session — queue (as JSON),
 * current index, position, and source tag. Mirrors
 * `flutter_client/lib/cache/db.dart`'s `CachedResumeState` Drift table.
 *
 * Lets a torn-down session (the player's idle/dismissed teardown)
 * resume on next launch; without it the headset / lock-screen play
 * button has nothing to act on. The Flutter codebase persists this on
 * every queue change and reads on cold start.
 *
 * The `json` field carries the entire ResumeState shape (queue trackrefs,
 * currentIndex, positionMs, sourceTag). Kotlin-side deserialization
 * happens in the ResumeController (Phase 6.5) so the schema stays
 * stable across resume-shape changes.
 */
@Entity(tableName = "cached_resume_state")
data class CachedResumeStateEntity(
    @PrimaryKey val id: Int = 1,
    val json: String,
    val updatedAt: Instant = Clock.System.now(),
)
