<?php
/**
 * Uninstall Maca Tjatt.
 *
 * @package Maca_Tjatt
 */

defined( 'WP_UNINSTALL_PLUGIN' ) || exit;

require_once dirname( __FILE__ ) . '/includes/maca-api.php';

maca_tjatt_api_on_uninstall();

global $wpdb;

if ( isset( $wpdb ) && ! empty( $wpdb ) ) {
	$table = $wpdb->prefix . 'maca_tjatt_chunks';
	// phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
}

$maca_tjatt_options = array(
	'maca_tjatt_enabled',
	'maca_tjatt_floating',
	'maca_tjatt_index_all_pages',
	'maca_tjatt_index_posts',
	'maca_tjatt_name',
	'maca_tjatt_avatar',
	'maca_tjatt_avatar_url',
	'maca_tjatt_avatar_size',
	'maca_tjatt_avatar_bg_color',
	'maca_tjatt_chat_model',
	'maca_tjatt_rate_limit',
	'maca_tjatt_page_ids',
	'maca_tjatt_custom_knowledge',
	'maca_tjatt_index_status',
);

foreach ( $maca_tjatt_options as $maca_tjatt_option ) {
	delete_option( $maca_tjatt_option );
}

wp_clear_scheduled_hook( 'maca_tjatt_daily_reindex' );
wp_clear_scheduled_hook( 'maca_tjatt_reindex_event' );

wp_cache_flush();
