<?php
/**
 * Class Noesia Cs Activator.
 *
 * @package Noesia_Commerce_Suite
 */

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

/**
 * Class implementation.
 */
class Noesia_CS_Activator {
	/**
	 * Handles the related plugin operation.
	 */
	public static function activate() {
		if ( ! get_option( 'noesia_cs_db_version' ) ) {
			add_option( 'noesia_cs_db_version', NOESIA_CS_VERSION, '', false );
		} else {
			update_option( 'noesia_cs_db_version', NOESIA_CS_VERSION, false );
		}

		if ( ! get_option( 'noesia_cs_settings' ) ) {
			add_option( 'noesia_cs_settings', Noesia_CS_Settings::defaults(), '', false );
		}

		add_rewrite_rule( '^noesia-care/([^/]+)/?$', 'index.php?noesia_cs_care_token=$matches[1]', 'top' );
		add_rewrite_rule( '^noesia-reorder-opt-out/([^/]+)/?$', 'index.php?noesia_cs_reorder_optout_token=$matches[1]', 'top' );
		add_rewrite_rule( '^noesia-care-action/([^/]+)/([^/]+)/?$', 'index.php?noesia_cs_care_action_token=$matches[1]&noesia_cs_care_action_type=$matches[2]', 'top' );

		if ( ! wp_next_scheduled( Noesia_CS_Reorder_Service::CRON_HOOK ) ) {
			wp_schedule_event( time() + HOUR_IN_SECONDS, 'hourly', Noesia_CS_Reorder_Service::CRON_HOOK );
		}

		flush_rewrite_rules();
	}
}
