<?php
/**
 * Uninstall handler for Kitgenix PDF Invoicing for WooCommerce.
 *
 * This file is executed when the plugin is uninstalled via the WordPress
 * admin. It removes plugin options stored in the database. We do NOT
 * remove order meta or user data to avoid accidental data loss.
 */

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

// Remove plugin options from single-site and network options.
delete_option( 'kitgenix_pdf_invoicing_settings' );
delete_site_option( 'kitgenix_pdf_invoicing_settings' );
delete_option( 'kitgenix_pdf_invoicing_event_log' );
delete_site_option( 'kitgenix_pdf_invoicing_event_log' );

// Remove anonymous metrics.
delete_option( 'kitgenix_pdf_invoicing_for_woocommerce_metrics' );
delete_site_option( 'kitgenix_pdf_invoicing_for_woocommerce_metrics' );

// Remove numbering sequence counters (legacy option-based fallback).
delete_option( 'kitgenix_pdf_invoicing_for_woocommerce_number_sequences' );
delete_site_option( 'kitgenix_pdf_invoicing_for_woocommerce_number_sequences' );

// Remove the atomic numbering sequences table (2.0.0+). Contains only
// integer counters – no order or customer data – so this is safe to drop
// unconditionally, same as any other plugin-owned option/table.
global $wpdb;
if ( isset( $wpdb ) ) {
    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'kitgenix_pdf_sequences' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Static, plugin-owned table name; no user input involved. Uninstall-time schema removal; a direct query is the only option and caching is not applicable to a DROP TABLE.
}

// Remove the upgrade/migration version marker.
delete_option( 'kitgenix_pdf_invoicing_for_woocommerce_db_version' );
delete_site_option( 'kitgenix_pdf_invoicing_for_woocommerce_db_version' );

// Remove custom font metadata. The uploaded font FILES themselves are left
// in place, same as archived PDFs below – uninstall does not delete files
// in the uploads directory to avoid irreversible data loss; site owners
// who want those removed too can delete the uploads sub-folder manually.
delete_option( 'kitgenix_pdf_invoicing_for_woocommerce_custom_fonts' );
delete_site_option( 'kitgenix_pdf_invoicing_for_woocommerce_custom_fonts' );

// Remove plugin-only transients.
delete_transient( 'kitgenix_pdf_invoicing_for_woocommerce_do_activation_redirect' );
