package il.co.organicai.agent

import android.content.Context

/**
 * Durable session token — the point of ADR-46 (eternal sessions) on mobile: log in
 * once, stay logged in. Persisted in SharedPreferences so it survives restarts.
 * (A production build should move this to EncryptedSharedPreferences.)
 */
object SessionStore {
    private const val PREF = "organicai"
    private const val KEY_TOKEN = "session_token"
    private const val KEY_ID = "identifier"

    fun token(ctx: Context): String? =
        ctx.getSharedPreferences(PREF, Context.MODE_PRIVATE).getString(KEY_TOKEN, null)

    fun save(ctx: Context, token: String, identifier: String) {
        ctx.getSharedPreferences(PREF, Context.MODE_PRIVATE).edit()
            .putString(KEY_TOKEN, token).putString(KEY_ID, identifier).apply()
    }

    fun clear(ctx: Context) {
        ctx.getSharedPreferences(PREF, Context.MODE_PRIVATE).edit().clear().apply()
    }
}
