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

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

/**
 * Per-item row driving the Home screen sections. Mirrors
 * `flutter_client/lib/cache/db.dart`'s `CachedHomeIndex` Drift table.
 *
 * `section` is one of (matching /api/home keys):
 *   - "recently_added_albums"
 *   - "rediscover_albums"
 *   - "rediscover_artists"
 *   - "most_played_tracks"
 *   - "last_played_artists"
 *   - "you_might_like_albums"
 *   - "you_might_like_artists"
 *
 * New `section` values need no schema change — the column stores the
 * string verbatim and the DAO keys on it.
 *
 * `entityType` is "album" | "artist" | "track" — dispatches hydration
 * to the right per-entity endpoint when a tile is rendered.
 *
 * The composite PK (section, position) means there's exactly one row
 * per slot per section; sync replaces in-place by upsert.
 */
@Entity(
    tableName = "cached_home_index",
    primaryKeys = ["section", "position"],
)
data class CachedHomeIndexEntity(
    val section: String,
    val position: Int,
    val entityType: String,
    val entityId: String,
    val fetchedAt: Instant = Clock.System.now(),
)
