<?php
/**
 * Settings controller.
 *
 * @package Fast-Events/Rest-API/Settings
 * @since 1.0
 * @since 1.2 Added 'ordering_api' and 'ordering_shortcodes'.
 * @since 1.4 - Added checking optional event_ids as part of the emailaddress suffix
 *            - Added Saas fields
 *            - Added cache time for order forms
 * @since 3.0.0 New settings structure.
 */

declare( strict_types=1 );
namespace FeData\FastEvents\RestAPI\Admin;

use FeData\FastEvents\Core\AdminUI;
use FeData\FastEvents\Logging\LoggerFactory;
use FeData\FastEvents\Payment\PaymentFactory;
use FeData\FastEvents\Storage\Options;
use FeData\FastEvents\Storage\PluginSettings;
use FeData\FastEvents\Utilities\SettingsDefaults;
use stdClass;
use WP_Error;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;

defined( 'ABSPATH' ) || exit;

/**
 * Settings class.
 */
final class SettingsController {

	/**
	 * Settings constructor.
	 *
	 * @since 1.0
	 *
	 * @param Options       $options  - The options' storage.
	 * @param AdminUI       $admin_ui - The admin UI.
	 * @param LoggerFactory $logger - The logger.
	 */
	public function __construct(
		private readonly Options $options,
		private readonly AdminUI $admin_ui,
		private readonly LoggerFactory $logger
	) {}

	/**
	 * Singletons should not be cloneable.
	 *
	 * @since 2.5.0
	 */
	private function __clone(): void {
	}

	/**
	 * Prevent from being unserialized.
	 *
	 * @since 2.5.0
	 */
	public function __wakeup(): void {
	}

	/**
	 * Register the routes for saving the plugin settings.
	 *
	 * @since 1.0
	 * @since 2.3.0 Added 'captcha_provider' (0 = Google, 1 = Cloudflare)
	 * @since 2.4.0 Added SMTP2GO email provider.
	 * @since 2.4.1 AWS SES regions is now a string
	 * @since 2.5.0 - Simplified the permission callback.
	 *              - Added 'log_retention_days'
	 * @since 3.0.0 - New settings structure.
	 */
	public function register_routes(): void {

		if ( ! current_user_can( 'manage_options' ) ) {
			return; // No permission.
		}

		// Save plugin settings.
		register_rest_route(
			'fast-events',
			'/v1/settings',
			array(
				'methods'             => WP_REST_Server::CREATABLE,
				'callback'            => array( $this, 'save_plugin_settings' ),
				'permission_callback' => function () {
					return current_user_can( 'manage_options' );
				},
				'args'                => array(
					'payment_config'           => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_textarea_field',
					),
					'currency'                 => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'currency_symbol'          => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'refund_costs'             => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'refund_per'               => array(
						'required' => true,
						'type'     => 'integer',
						'enum'     => array( 1, 2 ),
					),
					'expire'                   => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'cancel_url'               => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'errorpage'                => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'saas_client_id'           => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'saas_client_secret'       => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'saas_client_fee'          => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'saas_client_fee_per'      => array(
						'required' => true,
						'type'     => 'integer',
						'enum'     => array( 1, 2 ),
					),
					'mailer_config'            => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_textarea_field',
					),
					'email_retry_scheme'       => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'smtp_sender_name'         => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'smtp_sender_email'        => array(
						'required' => true,
						'type'     => 'string',
						'format'   => 'email',
					),
					'captcha_provider'         => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'captcha_site_key'         => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'captcha_secret_key'       => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'fe_admin_api_key'         => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),
					'misc_custom_order_status' => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_text_field',
					),

					'as_purge_days'            => array(
						'required'          => true,
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
					'as_time_limit'            => array(
						'required'          => true,
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
					'as_batch_size'            => array(
						'required'          => true,
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
					'as_concurrent_batches'    => array(
						'required'          => true,
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
					'as_additional_runners'    => array(
						'required'          => true,
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
					'log_level'                => array(
						'required' => true,
						'type'     => 'string',
						'enum'     => array( 'debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency' ),
					),
					'monolog_config'           => array(
						'required'          => true,
						'type'              => 'string',
						'sanitize_callback' => 'sanitize_textarea_field',
					),
					'log_retention_days'       => array(
						'required'          => true,
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
					'stats_queries_cache_time' => array(
						'required'          => true,
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
					'order_form_cache_time'    => array(
						'required'          => true,
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
				),
			),
		);

		// Install/update/check/delete Web interface.
		register_rest_route(
			'fast-events',
			'/v1/settings/mgt',
			array(
				array(
					'methods'             => WP_REST_Server::READABLE,
					'callback'            => array( $this, 'admin_ui_check' ),
					'permission_callback' => function () {
						return current_user_can( 'manage_options' );
					},
				),
				array(
					'methods'             => WP_REST_Server::CREATABLE,
					'callback'            => array( $this, 'admin_ui_install' ),
					'permission_callback' => function () {
						return current_user_can( 'manage_options' );
					},
				),
				array(
					'methods'             => WP_REST_Server::DELETABLE,
					'callback'            => array( $this, 'admin_ui_delete' ),
					'permission_callback' => function () {
						return current_user_can( 'manage_options' );
					},
				),
			),
		);

		// Set/unset auto update Web interface.
		register_rest_route(
			'fast-events',
			'/v1/settings/mgt/auto-update',
			array(
				'methods'             => WP_REST_Server::CREATABLE,
				'callback'            => array( $this, 'mgt_set_auto_update' ),
				'permission_callback' => function () {
					return current_user_can( 'manage_options' );
				},
				'args'                => array(
					'auto_update' => array(
						'required' => true,
						'type'     => 'boolean',
					),
				),
			),
		);

		// Clear all Action Scheduler jobs and create new jobs.
		register_rest_route(
			'fast-events',
			'/v1/settings/as/reset',
			array(
				'methods'             => WP_REST_Server::READABLE,
				'callback'            => array( $this, 'as_reset' ),
				'permission_callback' => function () {
					return current_user_can( 'manage_options' );
				},
			),
		);

		// Check if the recurring tasks are running and, if necessary, restart them.
		register_rest_route(
			'fast-events',
			'/v1/settings/as/check',
			array(
				'methods'             => WP_REST_Server::READABLE,
				'callback'            => array( $this, 'as_check' ),
				'permission_callback' => function () {
					return current_user_can( 'manage_options' );
				},
			),
		);
	}


	/**
	 * Save plugin settings
	 *
	 * @since 1.0
	 * @since 1.4   Added Saas fields
	 * @since 2.3.0 - Sendinblue is now Brevo. We keep using the old keynames for the API parameters.
	 *              - Added 'captcha_provider' (0 = Google, 1 = Cloudflare)
	 * @since 2.4.0 - Added SMTP2GO email provider.
	 * @since 2.5.0 - Added 'orders_cleanup' and 'log_retention_days'.
	 *
	 * @param WP_REST_Request $data Request instance.
	 *
	 * @return WP_Error|WP_REST_Response
	 */
	public function save_plugin_settings( WP_REST_Request $data ): WP_Error|WP_REST_Response {
		global $fevt_container;

		$params  = $data->get_params();
		$options = SettingsDefaults::default_settings();

		// Has the payment test mode been enabled?
		$options->payment_config->wait = ! empty( $params['payment_wait'] );

		// Has Saas mode been enabled?
		$options->payment_config->saas_mode = ! empty( $params['saas_mode'] );

		// Has Saas test been enabled?
		$options->payment_config->saas_test = ! empty( $params['saas_test'] );

		// Do we need to use email retries?
		$options->email_retries->enabled = ! empty( $params['email_retries'] );

		// Do we need to use email webhooks?
		$options->email_retries->webhooks = ! empty( $params['email_webhooks'] );

		// Do we need to use email queues?
		$options->email_retries->queues = ! empty( $params['email_queue'] );

		// Schedule orders clean-up?
		$options->misc->orders_cleanup = ! empty( $params['orders_cleanup'] );

		// Do we need to use the ordering API?
		$options->misc->ordering_api = ! empty( $params['ordering_api'] );

		// Check cancel URL.
		if ( ! empty( $params['cancel_url'] ) && false === filter_var( $params['cancel_url'], FILTER_VALIDATE_URL ) ) {
			return new WP_Error( 'invalid_setting', __( 'Invalid cancel URL', 'fast-events' ), array( 'status' => 400 ) );
		}
		// Check error page.
		if ( ! empty( $params['errorpage'] ) && false === filter_var( $params['errorpage'], FILTER_VALIDATE_URL ) ) {
			return new WP_Error( 'invalid_setting', __( 'Invalid error-page', 'fast-events' ), array( 'status' => 400 ) );
		}

		// Check for captcha provers.
		if ( '0' !== $params['captcha_provider'] && '1' !== $params['captcha_provider'] ) {
			return new WP_Error( 'invalid_setting', __( 'Invalid Captcha provider', 'fast-events' ), array( 'status' => 400 ) );
		}

		// Check email retry scheme.
		$email_retry_scheme = $params['email_retry_scheme'];
		if ( ! empty( $email_retry_scheme ) ) {
			$email_retry_scheme = implode( ',', array_map( 'intval', explode( ',', $email_retry_scheme ) ) );
		}

		if ( $options->email_retries->enabled && empty( $email_retry_scheme ) ) {
			$options->email_retries->retry_scheme = '2,4,8,16,32,64,128';
		} else {
			$options->email_retries->retry_scheme = $email_retry_scheme;
		}

		// Check the payment field if it is proper JSON.
		$payment = json_decode( $params['payment_config'] );
		if ( JSON_ERROR_NONE !== json_last_error() ) {
			return new WP_Error( 'invalid_setting', __( 'Payment configuration contains invalid JSON', 'fast-events' ), array( 'status' => 400 ) );
		}

		// Do some basic checking on the payment configuration.
		if ( ! isset( $payment->type ) || ! isset( $payment->provider ) || 'payment' !== $payment->type ) {
			return new WP_Error( 'invalid_setting', __( 'Payment configuration is missing required fields "type" or "provider"', 'fast-events' ), array( 'status' => 400 ) );
		}
		if ( ! isset( $payment->provider->class ) ) {
			return new WP_Error( 'invalid_setting', __( 'The required "class" field for the payment provider is missing', 'fast-events' ), array( 'status' => 400 ) );
		}
		if ( ! class_exists( $payment->provider->class ) ) {
			/* translators: 1: The name of the class */
			return new WP_Error( 'invalid_setting', sprintf( __( 'The payment class "%1$s" does not exist', 'fast-events' ), $payment->provider->class ), array( 'status' => 400 ) );

		}
		$payment_encoded = wp_json_encode( $payment );

		// Check the mailer field if it is proper JSON.
		$mailer = json_decode( $params['mailer_config'] );
		if ( JSON_ERROR_NONE !== json_last_error() ) {
			return new WP_Error( 'invalid_setting', __( 'Mailer configuration contains invalid JSON', 'fast-events' ), array( 'status' => 400 ) );
		}

		// Do some basic checking on the mailer configuration.
		if ( ! isset( $mailer->type ) || ! isset( $mailer->provider ) || 'mailer' !== $mailer->type ) {
			return new WP_Error( 'invalid_setting', __( 'Mailer configuration is missing required fields "type" or "provider"', 'fast-events' ), array( 'status' => 400 ) );
		}
		if ( ! isset( $mailer->provider->class ) ) {
			return new WP_Error( 'invalid_setting', __( 'The required "class" field for the mail provider is missing', 'fast-events' ), array( 'status' => 400 ) );
		}
		if ( ! class_exists( $mailer->provider->class ) ) {
			/* translators: 1: The name of the class */
			return new WP_Error( 'invalid_setting', sprintf( __( 'The mailer class "%1$s" does not exist', 'fast-events' ), $mailer->provider->class ), array( 'status' => 400 ) );

		}
		$mailer = wp_json_encode( $mailer );

		// Check the logging field if it is proper JSON.
		$logging = json_decode( $params['monolog_config'] );
		if ( JSON_ERROR_NONE !== json_last_error() ) {
			return new WP_Error( 'invalid_setting', __( 'Logging configuration contains invalid JSON', 'fast-events' ), array( 'status' => 400 ) );
		}

		// Do some basic checking on the logging configuration.
		if ( ! isset( $logging->type ) || ! isset( $logging->channel ) ) {
			return new WP_Error( 'invalid_setting', __( 'Logging configuration is missing required fields "type" or "channel"', 'fast-events' ), array( 'status' => 400 ) );
		}
		if ( ! isset( $logging->handlers ) || ! is_array( $logging->handlers ) ) {
			return new WP_Error( 'invalid_setting', __( 'Logging "handlers" field is missing or is not defined as an array', 'fast-events' ), array( 'status' => 400 ) );
		}
		foreach ( $logging->handlers as $handler ) {
			if ( ! isset( $handler->class ) || ! isset( $handler->args ) ) {
				return new WP_Error( 'invalid_setting', __( 'The logging handler is missing one of the required fields: "class" or "args"', 'fast-events' ), array( 'status' => 400 ) );
			}
			if ( ! class_exists( $handler->class ) ) {
				/* translators: 1: The name of the class */
				return new WP_Error( 'invalid_setting', sprintf( __( 'The logging class "%1$s" does not exist', 'fast-events' ), $handler->class ), array( 'status' => 400 ) );

			}
			if ( ! is_array( $handler->args ) ) {
				return new WP_Error( 'invalid_setting', __( 'The logging handler "args" field is not defined as an array', 'fast-events' ), array( 'status' => 400 ) );
			}
		}
		$logging = wp_json_encode( $logging );

		// If necessary, uninstall the previous payment provider.
		$prev_payment = $fevt_container->get( PluginSettings::class )->payment_config();
		if ( $prev_payment->provider->class !== $payment->provider->class ) {
			$fevt_container->get( PaymentFactory::class )->uninstall();
		}

		// Set the full stdClass of options.
		$options->payment_provider                     = $payment_encoded;
		$options->payment_config->currency             = $params['currency'];
		$options->payment_config->currency_symbol      = $params['currency_symbol'];
		$options->payment_config->refund_costs         = (float) $params['refund_costs'];
		$options->payment_config->refund_per           = (int) $params['refund_per'];
		$options->payment_config->expire               = (int) $params['expire'];
		$options->payment_config->cancel_url           = $params['cancel_url'];
		$options->payment_config->errorpage            = $params['errorpage'];
		$options->payment_config->saas_client_id       = $params['saas_client_id'];
		$options->payment_config->saas_client_secret   = $params['saas_client_secret'];
		$options->payment_config->saas_client_fee      = (float) $params['saas_client_fee'];
		$options->payment_config->saas_client_fee_per  = (int) $params['saas_client_fee_per'];
		$options->mail_provider                        = $mailer;
		$options->email_sender->name                   = $params['smtp_sender_name'];
		$options->email_sender->email                  = $params['smtp_sender_email'];
		$options->captcha->provider                    = (int) $params['captcha_provider'];
		$options->captcha->site_key                    = $params['captcha_site_key'];
		$options->captcha->secret_key                  = $params['captcha_secret_key'];
		$options->fe_admin_api_key                     = $params['fe_admin_api_key'];
		$options->action_scheduler->purge_days         = (int) $params['as_purge_days'];
		$options->action_scheduler->time_limit         = (int) $params['as_time_limit'];
		$options->action_scheduler->batch_size         = (int) $params['as_batch_size'];
		$options->action_scheduler->concurrent_batches = (int) $params['as_concurrent_batches'];
		$options->action_scheduler->additional_runners = (int) $params['as_additional_runners'];
		$options->logging->level                       = $params['log_level'];
		$options->logging->log_retention_days          = (int) $params['log_retention_days'];
		$options->logging->monolog                     = $logging;
		$options->misc->stats_queries_cache_time       = (int) $params['stats_queries_cache_time'];
		$options->misc->order_form_cache_time          = (int) $params['order_form_cache_time'];
		$options->misc->custom_order_status            = $params['misc_custom_order_status'];

		// Save settings.
		$this->options->set_plugin_settings( $options );
		$this->logger->info( __( 'The settings have been saved.', 'fast-events' ), array( 'type' => 'Settings' ) );

		// Install the payment provider.
		$fevt_container->get( PluginSettings::class )->reload_settings();
		if ( $prev_payment->provider->class === $payment->provider->class ) {
			$result = $fevt_container->get( PaymentFactory::class )->install();
			if ( is_wp_error( $result ) ) {
				return $result;
			}
			return rest_ensure_response( __( 'The settings have been saved.', 'fast-events' ) );
		}

		// The 201 is to signal the caller to redo the request and run the install-method of the payment provider.
		return new WP_REST_Response( __( 'The settings have been saved.', 'fast-events' ), 201 );
	}


	/**
	 * Check for a new version of the Web interface.
	 *
	 * @return WP_Error|WP_REST_Response
	 * @since 2.0
	 */
	public function admin_ui_check(): WP_Error|WP_REST_Response {
		$release = $this->admin_ui->get_latest_admin_interface();
		if ( is_wp_error( $release ) ) {
			return $release;
		}

		// Get the management options.
		$mgt                 = $this->options->get_management_settings();
		$mgt['last_checked'] = current_time( 'mysql' );

		// Is there a new version?
		if ( isset( $mgt['version'] ) && $mgt['version'] === $release['tag_name'] ) {
			$this->options->set_management_settings( $mgt );
			$this->logger->info( __( 'No new Web interface version available', 'fast-events' ), array( 'type' => 'Check Web Interface' ) );
			return rest_ensure_response(
				array(
					'update_available' => false,
					'message'          => __( 'No new Web interface version available', 'fast-events' ),
				)
			);
		}

		$mgt['new_version'] = $release['tag_name'];
		$mgt['new_changes'] = $release['body'];
		$this->options->set_management_settings( $mgt );
		$this->logger->info( __( 'New Web interface version available: ', 'fast-events' ) . $release['tag_name'], array( 'type' => 'Check Web Interface' ) );
		return rest_ensure_response(
			array(
				'update_available' => true,
				'new_version'      => $release['tag_name'],
				'new_changes'      => $release['body'],
			)
		);
	}


	/**
	 * Install/update Web interface.
	 *
	 * @return WP_Error|WP_REST_Response
	 * @since 2.0
	 * @since 2.0.3 Moved to uploads
	 * @since 2.5.0 Improved errors handling after failed download.
	 */
	public function admin_ui_install(): WP_Error|WP_REST_Response {
		return $this->admin_ui->install_admin_interface( $this->admin_ui::FE_ADMIN_UI_SETTINGS_INSTALL );
	}


	/**
	 * Delete the Web interface.
	 *
	 * @return WP_Error|WP_REST_Response
	 * @since 2.0
	 * @since 2.0.3 Changed to uploads
	 * @since 3.0.0 Moved execution to the Admin_UI class
	 */
	public function admin_ui_delete(): WP_Error|WP_REST_Response {
		$this->admin_ui->delete_admin_interface();
		return rest_ensure_response( __( 'Management interface deleted', 'fast-events' ) );
	}


	/**
	 * Clear all Action Scheduler jobs and create new jobs.
	 *
	 * @return WP_Error|WP_REST_Response
	 * @since 2.0
	 * @since 2.5.0 Also delete retry messages
	 */
	public function as_reset(): WP_Error|WP_REST_Response {
		global $wpdb;

		// Remove possible scheduled actions.
		as_unschedule_all_actions( 'fast_events_action_clean_cache' );
		as_unschedule_all_actions( 'fast_events_action_confirmation_timeout' );
		as_unschedule_all_actions( 'fast_events_action_payment_expire' );
		as_unschedule_all_actions( 'fast_events_action_send_mail' );
		as_unschedule_all_actions( 'fast_events_action_webhook' );

		// Delete any existing retry messages from the options table.
		$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'fast_events_email_msg%'" );

		// Re-schedule a recurring clean-up task for cleaning cache-dir.
		$this->restart_recurring_tasks();
		return rest_ensure_response( __( 'All the jobs have been deleted and the cleaning process has been restarted', 'fast-events' ) );
	}


	/**
	 * Check if Action Scheduler recurring jobs are scheduled and create new jobs if not.
	 *
	 * @return WP_Error|WP_REST_Response
	 * @since 2.5.0
	 */
	public function as_check(): WP_Error|WP_REST_Response {

		// Re-schedule a recurring clean-up task for cleaning cache-dir.
		$this->restart_recurring_tasks();
		return rest_ensure_response( __( 'The recurring jobs have been restarted', 'fast-events' ) );
	}


	/**
	 * Set auto update on or off.
	 *
	 * @param WP_REST_Request $data Request data.
	 *
	 * @return WP_Error|WP_REST_Response
	 * @since 2.0
	 */
	public function mgt_set_auto_update( WP_REST_Request $data ): WP_Error|WP_REST_Response {
		$mgt                = $this->options->get_management_settings();
		$mgt['auto_update'] = $data['auto_update'];

		// Reset the options.
		$this->options->set_management_settings( $mgt );

		if ( true === $mgt['auto_update'] ) {
			$this->logger->info( __( 'Automatic updating of the management interface is enabled', 'fast-events' ), array( 'type' => 'Management Interface' ) );
			return rest_ensure_response( __( 'Automatic updating of the management interface is enabled', 'fast-events' ) );
		} else {
			$this->logger->info( __( 'Automatic updating of the management interface is disabled', 'fast-events' ), array( 'type' => 'Management Interface' ) );
			return rest_ensure_response( __( 'Automatic updating of the management interface is disabled', 'fast-events' ) );
		}
	}


	/**
	 * Check if the recurring tasks are still there and restart them if necessary.
	 *
	 * @since 2.5.0
	 */
	private function restart_recurring_tasks(): void {

		// Re-schedule a recurring clean-up task for cleaning cache-dir.
		if ( ! as_has_scheduled_action( 'fast_events_action_clean_cache' ) ) {
			$this->logger->info( __( 'Restarted the "fast_events_action_clean_cache" task', 'fast-events' ), array( 'type' => 'Action-Scheduler' ) );
			as_schedule_recurring_action( time(), DAY_IN_SECONDS, 'fast_events_action_clean_cache' );
		}

		// Re-schedule the check for a new management interface?
		if ( ! empty( $this->options->get_management_settings() ) ) {
			if ( ! as_has_scheduled_action( 'fast_events_action_update_web' ) ) {
				$this->logger->info( __( 'Restarted the "fast_events_action_update_web" task', 'fast-events' ), array( 'type' => 'Action-Scheduler' ) );
				as_schedule_recurring_action( time(), DAY_IN_SECONDS, 'fast_events_action_update_web' );
			}
		}
	}
}
