<?php
namespace WPVOID\StockBeacon\Notifications;
if ( ! defined( 'ABSPATH' ) ) { exit; }
class RestockNotifier {
	private EmailManager $email_manager;
	public function __construct( EmailManager $email_manager ) {
		$this->email_manager = $email_manager;
	}
	public function trigger( int $product_id, int $variation_id = 0 ): void {
		$lock_key = 'stockbeacon_restock_sent_' . $product_id . '_' . $variation_id;
		if ( get_transient( $lock_key ) ) {
			return;
		}
		set_transient( $lock_key, 1, 5 * MINUTE_IN_SECONDS );
		$this->email_manager->schedule_restock_batch( $product_id, $variation_id );
	}
}
