package invalid.lena.rsend

import android.content.Context
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

// LastSync records the outcome of the most recent run so the dashboard can show
// it without opening the log.
object LastSync {

    private fun file(ctx: Context): File = File(ctx.filesDir, "last-sync")
    private val fmt = SimpleDateFormat("MM-dd HH:mm", Locale.US)

    fun set(ctx: Context, ok: Boolean) {
        file(ctx).writeText("${fmt.format(Date())} ${if (ok) "ok" else "FAILED"}")
    }

    fun get(ctx: Context): String = if (file(ctx).exists()) file(ctx).readText() else "never"
}
