package com.ponzischeme89.memby.update

/**
 * Chooses when the app should next ask for live update policy.
 *
 * A timeout and a positive "no update" response are deliberately different states. The
 * latter may wait for the regular policy poll; the former has learned nothing and retries
 * quickly before settling onto a bounded backoff.
 */
internal fun nextUpdateCheckDelay(
    requiredAttempts: Int,
    failedAttempts: Int,
    fastAttempts: Int,
    fastRetryMillis: Long,
    backoffMillis: Long,
    regularPollMillis: Long,
): Long = when {
    requiredAttempts in 1..fastAttempts -> fastRetryMillis
    requiredAttempts > fastAttempts -> backoffMillis
    failedAttempts in 1..fastAttempts -> fastRetryMillis
    failedAttempts > fastAttempts -> backoffMillis
    else -> regularPollMillis
}
