<?php

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

$options = [
    'datalumo_api_key',
    // Legacy (removed in favour of hardcoded URL)
    'datalumo_api_url',
    'datalumo_content_syncs',
    'datalumo_sync_states',
    'datalumo_chatbot_enabled',
    'datalumo_chatbot_integration_id',
    'datalumo_search_box_enabled',
    'datalumo_search_box_integration_id',
    'datalumo_search_enhanced',
    'datalumo_search_integration_id',
    'datalumo_search_post_types',
    'datalumo_search_summary_enabled',
    'datalumo_search_summary_selector',
    'datalumo_search_summary_position',
    // Legacy options (may exist from older versions)
    'datalumo_collection_id',
    'datalumo_post_types',
    'datalumo_last_sync',
    'datalumo_sync_total',
    'datalumo_sync_processed',
    'datalumo_sync_started',
];

foreach ($options as $option) {
    delete_option($option);
}

// Clean up per-sync state options (datalumo_sync_state_{id}).
global $wpdb;
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'datalumo\_sync\_state\_%'");

if (function_exists('as_unschedule_all_actions')) {
    as_unschedule_all_actions('datalumo_sync_entry', [], 'datalumo');
    as_unschedule_all_actions('datalumo_process_sync_batch', [], 'datalumo');
    as_unschedule_all_actions('datalumo_delete_sync_entries', [], 'datalumo');
}
