package de.trainingstagebuch.app.utils

import kotlin.math.min

object BackoffUtils {
    fun exponentialDelayMs(
        attempt: Int,
        initialDelayMs: Long = 1_000L,
        maxDelayMs: Long = 30_000L
    ): Long {
        val safeAttempt = attempt.coerceAtLeast(1)
        val exponent = (safeAttempt - 1).coerceAtMost(10)
        return min(initialDelayMs * (1L shl exponent), maxDelayMs)
    }
}
