<?php
/**
 * PayStarSea Crypto Payment Gateway Uninstall
 *
 * Fired when the plugin is uninstalled.
 *
 * @package PayStarSea
 * @since 1.0.0
 */

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

global $wpdb;

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange
$wpdb->query("DROP TABLE IF EXISTS `{$wpdb->prefix}seaxpay_orders`");
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange
$wpdb->query("DROP TABLE IF EXISTS `{$wpdb->prefix}seaxpay_logs`");

delete_option('seaxpay_version');
delete_option('seaxpay_db_version');
delete_option('woocommerce_seaxpay_settings');

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$merchant_options = $wpdb->get_results(
    "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE 'seaxpay_enabled_coins_%' OR option_name LIKE 'seaxpay_enabled_networks_%' OR option_name LIKE '_transient_seaxpay_%' OR option_name LIKE '_transient_timeout_seaxpay_%'"
);
if ($merchant_options) {
    // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
    foreach ($merchant_options as $option) {
        delete_option($option->option_name);
    }
}

wp_clear_scheduled_hook('seaxpay_check_expired_orders');

if (function_exists('as_unschedule_all_actions')) {
    as_unschedule_all_actions('seaxpay_check_expired_orders');
}
