<?php
/**
 * Loads the WooCommerce integration, and only then.
 *
 * @package SkyServers\Retragere
 */

declare(strict_types=1);

namespace SkyServers\Retragere\Wc;

use Automattic\WooCommerce\Utilities\FeaturesUtil;

/**
 * Everything under Wc/ assumes WooCommerce exists. Nothing here may run on a
 * plain WordPress install: the free-form declaration has to keep working.
 */
final class Bootstrap
{
    public static function isActive(): bool
    {
        return class_exists('WooCommerce') && function_exists('wc_get_orders');
    }

    /**
     * Declared before WooCommerce initialises, otherwise the store shows an
     * incompatibility warning even though every query here is HPOS safe.
     */
    public static function declareCompatibility(): void
    {
        if (class_exists(FeaturesUtil::class)) {
            FeaturesUtil::declare_compatibility('custom_order_tables', SSRC_FILE, true);
        }
    }

    public static function register(): void
    {
        if (!self::isActive()) {
            return;
        }

        MyAccount::register();
        LinesAjax::register();
        MetaProbe::register();
        Emails\Registrar::register();
    }
}
