<?php
namespace WPVOID\StockBeacon\Core;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Throttle {
	public function is_allowed( string $ip, int $limit = 5 ): bool {
		$limit = max( 1, $limit );
		$key   = 'stockbeacon_throttle_' . md5( $ip );
		$count = (int) get_transient( $key );
		if ( $count >= $limit ) {
			return false;
		}
		set_transient( $key, $count + 1, MINUTE_IN_SECONDS );
		return true;
	}
}
