<?php
/**
 * Public scan activity state.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Application\Scan;

/**
 * Derives a non-terminal activity label from checkpoint age.
 */
final class ScanActivity {
	/**
	 * @param string $status      Persisted scan status.
	 * @param int    $age_seconds Seconds since the last checkpoint.
	 * @return string
	 */
	public static function derive( $status, $age_seconds ) {
		if ( 'failed' === $status ) {
			return 'stopped';
		}
		if ( in_array( $status, array( 'completed', 'partial', 'cancelled' ), true ) ) {
			return 'finished';
		}
		$age_seconds = max( 0, (int) $age_seconds );
		if ( $age_seconds <= 20 ) {
			return 'working';
		}
		return $age_seconds <= 120 ? 'waiting' : 'inactive';
	}
}
