<?php
/**
 * Verbosity utility for log messages.
 * 
 * @package Ealab\Deployer
 */

namespace EaLab\WP_Deployer\vendor\Ealab\Deployer\Utility;

/**
 * Verbosity utility for log messages.
 */
class Verbosity {
	public const VERBOSITY_0 = 0;
	public const VERBOSITY_1 = 1;
	public const VERBOSITY_2 = 2;
	public const VERBOSITY_3 = 3;

	/**
	 * For messages that are temporarily disabled.
	 */
	public const VERBOSITY_DEACTIVATED = 1000;

	/**
	 * Available verbosity levels.
	 *
	 * @return int[] Array of available verbosity levels.
	 */
	private static function getVerbosityLevels(): array {
		return array(
			static::VERBOSITY_0,
			static::VERBOSITY_1,
			static::VERBOSITY_2,
			static::VERBOSITY_3,
			static::VERBOSITY_DEACTIVATED,
		);
	}

	/**
	 * Validates the given verbosity level.
	 *
	 * @param mixed $verbosity The value to validate. If true, will give the maximum verbosity level.
	 *
	 * @return int The usable verbosity level. If invalid, gives VERBOSITY_2.
	 */
	public static function validateVerbosityLevel( $verbosity ): int {
		$verbosity = true === $verbosity ? static::VERBOSITY_3 : $verbosity;

		return in_array( (int) $verbosity, static::getVerbosityLevels(), true )
			? (int) $verbosity
			: static::VERBOSITY_2;
	}

	/**
	 * Tells if the verbosity is at least the specified level.
	 *
	 * @param int $verbosity The verbosity level to check.
	 * @param int $expected_minimal_level Minimal level.
	 *
	 * @return bool True if at least the specified level.
	 */
	public static function verbosityIsAtLeast( int $verbosity, int $expected_minimal_level ): bool {
		return $verbosity >= $expected_minimal_level;
	}
}
