<?php
/**
 * Uninstall routine: removes all plugin data.
 *
 * @package Lucrativeit_Subscription_Recurring_Billing
 */

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

global $wpdb;

$lucrsure_tables = array( 'branches', 'customers', 'plans', 'subscriptions', 'invoices', 'roles', 'staff', 'plan_categories' );

$lucrsure_table_prefixes = array(
	$wpdb->prefix . 'lucrsure_',
	$wpdb->prefix . 'lsp_',
	$wpdb->prefix . 'lsr_',
);

foreach ( $lucrsure_table_prefixes as $lucrsure_table_prefix ) {
	foreach ( $lucrsure_tables as $lucrsure_table ) {
		$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
			$wpdb->prepare( 'DROP TABLE IF EXISTS %i', $lucrsure_table_prefix . $lucrsure_table ) // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,PluginCheck.Security.DirectDB.UnescapedDBParameter
		);
	}
}

$lucrsure_option_suffixes = array(
	'settings',
	'email_templates',
	'email_layout',
	'db_version',
	'activated_at',
	'onboarding_dismissed',
	'demo_data_imported',
	'demo_import_state',
	'activation_redirect',
	'dependency_status',
	'plan_schema_version',
	'branch_schema_version',
	'category_repair_version',
	'category_plan_pages',
	'prefix_migrated',
);

$lucrsure_option_prefixes = array( 'lucrsure_', 'lsp_', 'lsr_' );

foreach ( $lucrsure_option_prefixes as $lucrsure_option_prefix ) {
	foreach ( $lucrsure_option_suffixes as $lucrsure_option_suffix ) {
		delete_option( $lucrsure_option_prefix . $lucrsure_option_suffix );
	}
}

wp_clear_scheduled_hook( 'lucrsure_daily_billing_cron' );
wp_clear_scheduled_hook( 'lsp_daily_billing_cron' );
wp_clear_scheduled_hook( 'lsr_daily_billing_cron' );
