<?php
defined( 'ABSPATH' ) || exit;

/**
 * Registers all hooks for every module.
 *
 * Free tier:
 *   - Role-based exemption (Tax-Exempt Roles setting)
 *   - Per-user override: always / never / follow role rules (user profile)
 *   - Status column + filter on the Users list screen
 *   - WooCommerce session exemption
 *   - Order stamping, badge, order notes
 *   - My Account status notice
 *   - Invoice plugin integration
 *   - Developer filters (rankd_tx_skip_user, rankd_tx_exemption_sources, etc.)
 *
 * Pro tier (requires valid Freemius license):
 *   - Certificate submission form + file upload
 *   - Admin review queue (approve, reject, revoke, edit, bulk, add manual)
 *   - Dashboard widget
 *   - CSV exports (expiry, active, audit log)
 *   - Full email suite (admin notify, approved, rejected, expiry warning, expired)
 */
class Rankd_Tx_Loader {

	public static function init() {
		// Run DB upgrades on every load — skips instantly if already up to date.
		Rankd_Tx_Install::maybe_upgrade();

		// Flush rewrite rules on init when flagged (priority 20 — after the
		// Pro My Account endpoint is registered so it lands in the new rules).
		add_action( 'init', array( 'Rankd_Tx_Install', 'maybe_flush_rewrite_rules' ), 20 );

		// ── Core (always) ────────────────────────────────────────────────
		Rankd_Tx_Capabilities::init();
		Rankd_Tx_Exemption::init();

		// ── Admin (always) ───────────────────────────────────────────────
		Rankd_Tx_Admin::init();
		Rankd_Tx_User_Profile::init();
		Rankd_Tx_Users_List::init();
		Rankd_Tx_Order_Meta::init();
		Rankd_Tx_Invoice::init();

		// ── Customer-facing (always) ──────────────────────────────────────
		Rankd_Tx_My_Account::init();

		// ── Pro-only modules ──────────────────────────────────────────────
		// Freemius strips this entire block from the free build (the
		// condition calls a __premium_only method), and every class in it
		// lives in a file that is also stripped. Emails and cron therefore
		// only run with a valid license, matching the certificate source
		// itself, which is license-gated in Rankd_Tx_Exemption.
		if ( ( function_exists( 'rankd_tx_fs' ) && rankd_tx_fs()->can_use_premium_code__premium_only() ) ) {
			Rankd_Tx_Cron::init();
			Rankd_Tx_Emails::init();
			Rankd_Tx_Review_Queue::init();
			Rankd_Tx_Submission::init();
			Rankd_Tx_Dashboard::init();
			Rankd_Tx_Export::init();
			Rankd_Tx_Pro::init();
		}
	}
}
