<?php
/**
 * Uninstall - Cleanup on plugin deletion
 *
 * @package ContentReply_AI
 */

// Exit if not called by WordPress
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    exit;
}

global $wpdb;

// Drop custom tables
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wpsc_content_chunks" );
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wpsc_conversations" );
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared

// Delete options
$wpsc_options = array(
    'wpsc_api_key',
    'wpsc_ai_model',
    'wpsc_widget_position',
    'wpsc_primary_color',
    'wpsc_welcome_message',
    'wpsc_bot_name',
    'wpsc_fallback_message',
    'wpsc_contact_url',
    'wpsc_post_types',
    'wpsc_excluded_pages',
    'wpsc_max_tokens',
    'wpsc_show_on_mobile',
    'wpsc_auto_index',
    'wpsc_enabled',
    'wpsc_last_indexed',
);

foreach ( $wpsc_options as $wpsc_option ) {
    delete_option( $wpsc_option );
}

// Clear scheduled cron
wp_clear_scheduled_hook( 'wpsc_index_content' );
