<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class WOSR_Uninstall_Cleanup {
    public static function run() {
        if ( get_option('wosr_delete_data_on_uninstall') === '1' ) {
            global $wpdb;
            $tables = [
				'order_status',
				'order_status_overview',
			];

			foreach ( $tables as $table ) {
				$table_name = $wpdb->prefix . 'wosr_' . preg_replace( '/[^a-zA-Z0-9_]/', '', $table );
				$sql = "DROP TABLE IF EXISTS `$table_name`";

                // Reason: Custom plugin tables must be dropped manually. Table names are whitelisted and sanitized, $wpdb->prepare() not applicable.
                // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 
                $wpdb->query( $sql );
			}

        }
    }
}

if ( function_exists( 'ormfw_wosr_fs' ) ) {
    // Hook it
    ormfw_wosr_fs()->add_action('after_uninstall', ['WOSR_Uninstall_Cleanup', 'run']);
}