<?php declare(strict_types = 0);
/*
** Copyright (C) 2021-2026 initMAX s.r.o.
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/


namespace Modules\TetrisMAX\Includes;

/**
 * How fast the pieces fall.
 *
 * The STORED values are what a dashboard means, so they are named in one place
 * and both trees - the 6.4 - 7.4 form and the 6.0/6.2 one - use these
 * constants. A stored `speed = 2` has to keep meaning FAST after an in-place
 * Zabbix upgrade, in either direction.
 *
 * A plain class rather than an enum: Zabbix 6.0 and 6.2 run on PHP 7.4.
 */
final class Speed {

	public const SLOW = 0;
	public const NORMAL = 1;
	public const FAST = 2;

	/**
	 * Milliseconds between two automatic drops at level 1.
	 *
	 * The client speeds up from here with every level; this only decides where
	 * the game starts. NORMAL is the pace the widget has always had.
	 */
	private const INTERVALS = [
		self::SLOW => 800,
		self::NORMAL => 500,
		self::FAST => 300
	];

	public static function intervalMs($speed): int {
		$speed = (int) $speed;

		return self::INTERVALS[$speed] ?? self::INTERVALS[self::NORMAL];
	}
}
