<?php
/**
 * Factory bootstrap for Stocktake. The ONLY place that wires the shared core
 * to this plugin — Strauss rewrites these core references at build time.
 *
 * The product itself still lives in includes/ (STWC_* classes, classmap-
 * autoloaded): the 145-check live suite proved that code, so the factory
 * migration deliberately changes the wiring, not the engine.
 *
 * @package ErenLabs\Stocktake
 */

namespace ErenLabs\Stocktake;

use ErenLabs\Stocktake\Vendor\Hakki\WooCore\Core;

defined( 'ABSPATH' ) || exit;

final class Bootstrap {

	private const SLUG = 'stocktake-for-woocommerce';

	/** @var Core|null */
	private static $core = null;

	/**
	 * Build (or fetch) the shared core for this plugin. Core::boot() also
	 * declares HPOS + checkout-blocks compatibility.
	 */
	public static function core(): Core {
		if ( null === self::$core ) {
			self::$core = Core::boot(
				array(
					'slug'         => self::SLUG,
					'file'         => defined( 'STWC_FILE' ) ? STWC_FILE : __FILE__,
					'version'      => defined( 'STWC_VERSION' ) ? STWC_VERSION : '0.0.0',
					'group'        => 'b2b',
					'requires_woo' => true,
					'min_woo'      => '7.0',
					// Freemius later supplies the 'can' resolver (licence check).
				)
			);
		}
		return self::$core;
	}

	/**
	 * Free-yields-to-pro guard (Core::should_boot): when the pro artifact is
	 * co-installed it defines STOCKTAKE_FOR_WOOCOMMERCE_PRO_ACTIVE with its own
	 * file path, and any OTHER instance of this plugin steps aside.
	 */
	public static function should_boot(): bool {
		return self::core()->should_boot();
	}
}
