<?php

namespace WPProofShield\Security;

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


final class ReplayGuard {

	public function consumeNonce( string $nonce, int $ttl ): bool {
		$key = 'wpsh_replay_' . md5( $nonce );

		if ( get_transient( $key ) ) {
			return false;
		}

		set_transient( $key, 1, $ttl );

		// Mirror into external object cache when available, but do not trust
		// per-request in-memory cache for replay decisions.
		if ( function_exists( 'wp_using_ext_object_cache' ) && wp_using_ext_object_cache() && function_exists( 'wp_cache_set' ) ) {
			wp_cache_set( $key, 1, 'wpsh', $ttl );
		}

		return true;
	}
}
