<?php
/**
 * Fired when the plugin is uninstalled.
 *
 * @package LolaCore
 */

declare(strict_types=1);

// If uninstall not called from WordPress, then exit.
if (!defined('WP_UNINSTALL_PLUGIN')) {
    exit;
}

// Ensure the schema class is available
require_once __DIR__ . '/src/Database/Schema.php';

// Drop all LolaCore tables
\LolaCore\Database\Schema::drop();

// Delete options
delete_option('lolacore_db_version');
delete_option('lolacore_activated_at');

// Delete transients
global $wpdb;
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Uninstall cleanup.
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_lolacore\_%'");
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Uninstall cleanup.
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\_lolacore\_%'");

// Clear any scheduled hooks
wp_clear_scheduled_hook('lolacore_daily_decay');
wp_clear_scheduled_hook('lolacore_log_cleanup');