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

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

/**
 * Single-row table holding the user's session cookie, configured
 * server base URL, the serialized current user identity, and the
 * theme-override preference.
 *
 * `id = 0` is the only valid row. `sessionCookie` is null when the
 * user is logged out (or has never logged in). `baseUrl` always has
 * a value — `AuthStore.DEFAULT_BASE_URL` is used until the user
 * configures one in Settings. `userJson` is the JSON-encoded
 * UserRef captured at sign-in so the username + isAdmin survive
 * a cold restart (the cookie alone doesn't carry identity).
 * `themeMode` is "system" / "light" / "dark" (or null = system).
 *
 * The table is the de-facto single-row app-prefs row at this point,
 * not strictly auth-only. Kept under the auth_session name to avoid
 * a schema-rename migration; a future cleanup could rename to
 * `app_preferences`.
 */
@Entity(tableName = "auth_session")
data class AuthSessionEntity(
    @PrimaryKey val id: Int = 0,
    val sessionCookie: String? = null,
    val baseUrl: String,
    val userJson: String? = null,
    val themeMode: String? = null,
    val clientId: String? = null,
    /**
     * JSON-encoded CacheSettings (cache/audiocache/CacheSettings.kt).
     * Null = use defaults. Stored as a JSON blob rather than four
     * individual columns to keep schema changes cheap when the
     * CacheSettings shape evolves.
     */
    val cacheSettingsJson: String? = null,
    /**
     * Per-device opt-out of diagnostics reporting (M9). When the
     * account's debug mode is enabled by an admin, the user can still
     * turn reporting OFF on this device (battery/privacy) — that local
     * choice lives here. Default false = honor the account flag.
     */
    val diagnosticsOptOut: Boolean = false,
)
