<?php
// If uninstall not called from WordPress, exit
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
	exit;
}

// Delete plugin options - AI providers
delete_option( 'saiap_openai_api_key' );
delete_option( 'saiap_openai_model' );
delete_option( 'saiap_anthropic_api_key' );
delete_option( 'saiap_anthropic_model' );
delete_option( 'saiap_gemini_api_key' );
delete_option( 'saiap_gemini_model' );
delete_option( 'saiap_default_provider' );
delete_option( 'saiap_model' );

// Delete plugin options - content settings
delete_option( 'saiap_ai_prompt' );
delete_option( 'saiap_post_type' );
delete_option( 'saiap_link_field_name' );
delete_option( 'saiap_enable_prompt_history' );
delete_option( 'saiap_posts_per_week' );
delete_option( 'saiap_review_before_publish' );
delete_option( 'saiap_autopilot_enabled' );

// Delete plugin options - site context
delete_option( 'saiap_site_context' );
delete_option( 'saiap_custom_site_context' );
delete_option( 'saiap_context_cache' );
delete_option( 'saiap_context_last_updated' );
delete_option( 'saiap_context_post_limit' );
delete_option( 'saiap_context_post_age' );
delete_option( 'saiap_context_auto_loaded' );

// Delete plugin options - notifications
delete_option( 'saiap_notify_on_schedule' );
delete_option( 'saiap_notify_recipients' );

// Delete plugin options - tracking/analytics
delete_option( 'saiap_tracking_consent' );
delete_option( 'saiap_tracking_notice_shown' );
delete_option( 'saiap_tracking_prompt_shown' );

// Delete plugin options - licensing
delete_option( 'saiap_license_key' );
delete_option( 'saiap_license_invalid' );
delete_option( 'saiap_activation_data' );

// Delete plugin options - versioning
delete_option( 'saiap_db_version' );
delete_option( 'saiap_last_version_seen' );

// Delete trial/onboarding options
delete_option( 'saiap_trial_status' );
delete_option( 'saiap_trial_started_at' );
delete_option( 'saiap_trial_expires_at' );
delete_option( 'saiap_trial_license_key' );
delete_option( 'saiap_trial_source' );
delete_option( 'saiap_trial_onboarding_dismissed' );
delete_option( 'saiap_onboarding_wizard_data' );
delete_option( 'saiap_onboarding_dismissed' );
delete_option( 'saiap_premium_onboarding_dismissed' );
delete_option( 'saiap_setup_triggered_at' );
delete_option( 'saiap_setup_complete' );
delete_option( 'saiap_first_post_created' );
delete_option( 'saiap_web_wizard_data' );
delete_option( 'saiap_wizard_prefill_data' );

// Delete plugin options - AEO/head code
delete_option( 'saiap_custom_head_code' );

// Delete transients
delete_transient( 'saiap_show_tracking_notice' );
delete_transient( 'saiap_license_last_check' );
delete_transient( 'saiap_site_context_data' );
delete_transient( 'saiap_activation_redirect' );
delete_transient( 'saiap_models_registry_v1' );
delete_transient( 'saiap_show_trial_update_notice' );
delete_transient( 'saiap_calendar_items_count' );

// Drop custom database tables
global $wpdb;
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}saiap_prompts" );
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}saiap_prompt_posts" );
