package com.fabledsword.minstrel.player.output

/** Action the idle-revert collector should take on a player-state change. */
internal enum class IdleRevertAction { ARM, CANCEL, IGNORE }

/**
 * Pure decision for the UPnP idle-revert timer. [armed] is whether the
 * idle timer Job is currently running. We ARM only on the transition INTO
 * "engaged + not playing" (so repeated paused emissions don't reset the
 * countdown), CANCEL whenever playback resumes or UPnP disengages, and
 * otherwise IGNORE.
 */
internal fun idleRevertAction(
    upnpEngaged: Boolean,
    isPlaying: Boolean,
    armed: Boolean,
): IdleRevertAction = when {
    upnpEngaged && !isPlaying -> if (armed) IdleRevertAction.IGNORE else IdleRevertAction.ARM
    armed -> IdleRevertAction.CANCEL
    else -> IdleRevertAction.IGNORE
}
