<?php

declare(strict_types=1);

namespace CloudXM\SDK\WooCommerce\Compatibility;

/**
 * Helper class to declare compatibility with WooCommerce High-Performance Order Storage (HPOS).
 *
 * This class wraps WooCommerce's FeaturesUtil::declare_compatibility() method and hooks it to
 * the 'before_woocommerce_init' action to ensure proper timing.
 *
 * @see \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility()
 */
class HposCompatibility
{
    /**
     * Declare HPOS compatibility if the FeaturesUtil class exists.
     *
     * Calls WooCommerce's FeaturesUtil::declare_compatibility('custom_order_tables', $pluginFile, true)
     * to indicate this plugin is compatible with High-Performance Order Storage.
     *
     * @param string $pluginFile Full absolute path to the main plugin file (e.g., __FILE__)
     */
    public static function declare(string $pluginFile): void
    {
        add_action('before_woocommerce_init', function () use ($pluginFile) {
            if (class_exists('\\Automattic\\WooCommerce\\Utilities\\FeaturesUtil')) {
                \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
                    'custom_order_tables',
                    $pluginFile,
                    true
                );
            }
        });
    }
}
