<?php
/**
 * Uninstall script for Invoicing Integration for iFirma and WooCommerce
 * 
 * This file is executed when the plugin is deleted via WordPress admin.
 */

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

/**
 * Run uninstall cleanup.
 *
 * Wrapped in a function to avoid defining globals in file scope.
 *
 * @return void
 */
function devikit_ifirma_uninstall() {
	$devikit_ifirma_settings  = get_option( 'devikit_ifirma_settings', [] );
	$devikit_ifirma_keep_data = isset( $devikit_ifirma_settings['keep_data_on_uninstall'] ) && $devikit_ifirma_settings['keep_data_on_uninstall'] === 'yes';

	if ( $devikit_ifirma_keep_data ) {
		return;
	}

	// Delete plugin options.
	delete_option( 'devikit_ifirma_settings' );
	delete_option( 'devikit_ifirma_banner_dismissed' );
	delete_option( 'devikit_ifirma_banner_remind_later' );

	// Note: We intentionally do NOT attempt to bulk-delete transients by DB query here.
	// They are temporary and will expire naturally.
}

devikit_ifirma_uninstall();

// Note: We don't delete order meta (_ifirma_invoice_id, _ifirma_invoice_number, etc.)
// as this data may be needed for accounting purposes even after plugin removal.
