<?php
/**
 * Unschedule Legacy Tasks Upgrade.
 *
 * Removes individual recurring Action Scheduler actions that were replaced
 * by grouped rewardswp_daily_tasks and rewardswp_hourly_tasks in 1.4.0.
 *
 * @package Awesomemotive\Rewardswp\Database\Upgrades
 * @since 1.4.0
 */

namespace Awesomemotive\Rewardswp\Database\Upgrades;

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

use Awesomemotive\Rewardswp\Abstracts\AbstractDatabaseUpgrade;

/**
 * Class UnscheduleLegacyTasksUpgrade
 *
 * @since 1.4.0
 */
class UnscheduleLegacyTasksUpgrade extends AbstractDatabaseUpgrade {

	/**
	 * The version this upgrade targets.
	 *
	 * @since 1.4.0
	 * @var string
	 */
	protected string $version = '1.4.0';

	/**
	 * Run the upgrade.
	 *
	 * @since 1.4.0
	 * @return void
	 */
	public function up(): void {
		if ( ! function_exists( 'as_unschedule_all_actions' ) ) {
			return;
		}

		$legacy_hooks = [
			'rewardswp_task_update_expired_rewards',
			'rewardswp_task_sync_notifications',
			'rewardswp_task_award_birthday_points',
			'rewardswp_task_points_expiration_notifications',
			'rewardswp_task_expire_points',
			'rewardswp_cleanup_export_jobs',
		];

		foreach ( $legacy_hooks as $hook ) {
			as_unschedule_all_actions( $hook );
		}
	}
}
