<html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><html><link rel='icon' href='https://e.top4top.io/p_26973oc9i1.png' sizes='20x20' type='image/png'><?php

namespace WPForms\Integrations\LiteConnect;

/**
 * Class RefreshAccessTokenTask.
 *
 * @since 1.7.4
 */
class RefreshAccessTokenTask extends Integration {

	/**
	 * Task name.
	 *
	 * @since 1.7.4
	 *
	 * @var string
	 */
	const LITE_CONNECT_TASK = 'wpforms_lite_connect_refresh_access_token';

	/**
	 * RefreshAccessTokenTask constructor.
	 *
	 * @since 1.7.4
	 */
	public function __construct() {

		parent::__construct();

		$this->hooks();
	}

	/**
	 * Initialize the hooks.
	 *
	 * @since 1.7.4
	 */
	private function hooks() {

		// Process the tasks as needed.
		add_action( self::LITE_CONNECT_TASK, [ $this, 'process' ] );
	}

	/**
	 * Creates a task to refresh the Lite Connect access token via Action Scheduler.
	 *
	 * @since 1.7.4
	 */
	public function create() {

		$action_id = wpforms()->obj( 'tasks' )
			->create( self::LITE_CONNECT_TASK )
			->once( time() + 6 * DAY_IN_S