<?php
/**
 * Uninstall controller for plugin removal.
 *
 * @package Awesomemotive\Rewardswp\Controllers
 * @since 1.0.0
 */

namespace Awesomemotive\Rewardswp\Controllers;

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

use Awesomemotive\Rewardswp\Interfaces\ControllerInterface;
use Awesomemotive\Rewardswp\Controllers\TaskSchedulerController;

/**
 * Uninstall Controller.
 *
 * @since 1.0.0
 */
class UninstallController implements ControllerInterface {
	/**
	 * Task scheduler controller instance.
	 *
	 * @since 1.0.6
	 *
	 * @var TaskSchedulerController
	 */
	private TaskSchedulerController $task_scheduler_controller;

	/**
	 * Constructor.
	 *
	 * @since 1.0.6
	 *
	 * @param TaskSchedulerController $task_scheduler_controller Task scheduler controller instance.
	 */
	public function __construct( TaskSchedulerController $task_scheduler_controller ) {
		$this->task_scheduler_controller = $task_scheduler_controller;
	}

	/**
	 * Execute routines on uninstall.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public function init() {
		$this->task_scheduler_controller->unschedule_recurring_actions();

		// Flush rewrite rules to remove custom endpoints.
		flush_rewrite_rules();
	}
}
