<?php
/**
 * TitanCart Notifications Module
 *
 * Wires the admin notification source (event listeners on the engine's own
 * action hooks) and registers the REST surface the SPA bell consumes.
 *
 * KI-26 (S304). Self-contained: own table/ORM (NotificationManager), own REST
 * (NotificationsController, titancart/v1/notifications), and WordPress actions
 * only as the thin event layer — the listeners hook the same `titancart_order_committed`
 * / `tcmp_vendor_created` actions the engine and marketplace already fire.
 *
 * @package TitanCart\Modules\Notifications
 */

namespace TitanCart\Modules\Notifications;

use TitanCart\REST\Notifications\NotificationsController;

defined( 'ABSPATH' ) || exit;

class NotificationsModule {

	public static function init(): void {
		// Event sources → notifications.
		// Genuine paid commit (fired once per order) — NOT titancart_order_placed,
		// which fires before the payment outcome is known / on declined orders.
		add_action( 'titancart_order_committed', [ NotificationManager::class, 'on_order_committed' ], 20, 1 );
		// Marketplace vendor applications. The action only fires where the
		// marketplace extension is active, so this self-disables on a plain store.
		add_action( 'tcmp_vendor_created', [ NotificationManager::class, 'on_vendor_created' ], 10, 3 );

		// REST surface for the SPA bell.
		add_action( 'rest_api_init', [ self::class, 'register_routes' ] );
	}

	public static function register_routes(): void {
		( new NotificationsController() )->register_routes();
	}
}
