package com.fabledsword.minstrel.cache.audiocache

import kotlinx.serialization.Serializable

private const val FIVE_GIB_BYTES = 5L * 1024 * 1024 * 1024
private const val DEFAULT_PREFETCH_WINDOW = 5

/**
 * User-tunable audio cache settings. Mirrors Flutter's `CacheSettings`
 * (cache_settings_provider.dart) field-for-field. Persisted as a JSON
 * blob on the auth_session single-row table via [AuthStore].
 *
 * - [likedCapBytes]: budget for cached files of liked tracks. 0 means
 *   unlimited. Effective at next app start (SimpleCache is built once
 *   per process).
 * - [rollingCapBytes]: budget for incidental / auto-prefetch downloads.
 *   Same 0=unlimited / restart-to-apply caveat.
 * - [prefetchWindow]: 1..10. Number of next-tracks the prefetcher
 *   pre-downloads. Has no effect until the prefetcher lands (separate
 *   audit follow-up) — persisted now so the user can pre-configure.
 * - [cacheLikedTracks]: when true, liking a track should also pin its
 *   audio to the liked-cache bucket. Has no effect until pin-on-like
 *   lands (separate follow-up).
 *
 * Defaults match Flutter: 5 GiB per bucket, prefetch=5, cache-liked=true.
 */
@Serializable
data class CacheSettings(
    val likedCapBytes: Long = FIVE_GIB_BYTES,
    val rollingCapBytes: Long = FIVE_GIB_BYTES,
    val prefetchWindow: Int = DEFAULT_PREFETCH_WINDOW,
    val cacheLikedTracks: Boolean = true,
) {
    companion object {
        val DEFAULT: CacheSettings = CacheSettings()
    }
}
