<?php
/**
 * API Module Bootstrap
 *
 * @package AmbassadorHub\Api
 */

namespace AmbassadorHub\Api;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * API module - handles REST API endpoints.
 *
 * Manages REST API namespace, routes, and authentication.
 */
final class ApiModule {
	/**
	 * REST API namespace.
	 */
	public const NAMESPACE = 'ambassadorhub/v1';

	/**
	 * Initialize the API module.
	 *
	 * @return void
	 */
	public static function init(): void {
		add_action( 'rest_api_init', array( self::class, 'register_routes' ) );

		/**
		 * Fires when API module is initialized.
		 *
		 * @since 0.1.0
		 */
		do_action( 'ambh_api_module_init' );
	}

	/**
	 * Register REST API routes.
	 *
	 * @return void
	 */
	public static function register_routes(): void {
		/**
		 * Fires when core modules should register their REST routes.
		 *
		 * Internal core modules (Accounts, Automations, etc.) hook here
		 * to register their API endpoints before external plugins.
		 *
		 * @since 0.1.0
		 */
		do_action( 'ambh_register_rest_routes' );

		/**
		 * Fires after core REST routes are registered.
		 *
		 * External feature plugins and add-ons should hook here to register
		 * their REST routes after all core module routes are available.
		 *
		 * @since 0.1.0
		 */
		do_action( 'ambh_rest_routes_registered' );
	}

	/**
	 * Get the REST API namespace.
	 *
	 * @return string
	 */
	public static function get_namespace(): string {
		return self::NAMESPACE;
	}
}
