<?php
/**
 * TitanCart Reports Module — Module 12
 *
 * Bootstraps the Reports & Analytics module:
 *  - Registers REST routes via ReportsController
 *  - Schedules hourly cron for export file cleanup
 *
 * Usage in Plugin::boot():
 *   ReportsModule::init();  // Module 12 — Reports & Analytics
 *
 * @package TitanCart\Modules\Reports
 */

namespace TitanCart\Modules\Reports;

use TitanCart\REST\Reports\ReportsController;

defined( 'ABSPATH' ) || exit;

class ReportsModule {

	public static function init(): void {
		add_action( 'rest_api_init', [ self::class, 'registerRoutes' ] );
		add_filter( 'cron_schedules', [ self::class, 'addCronSchedule' ] );
	}

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

	/**
	 * Ensure a titancart_hourly schedule exists (reused by other modules if present).
	 */
	public static function addCronSchedule( array $schedules ): array {
		if ( ! isset( $schedules['titancart_hourly'] ) ) {
			$schedules['titancart_hourly'] = [
				'interval' => HOUR_IN_SECONDS,
				// Plain string ON PURPOSE (S468): cron_schedules is applied
				// pre-init whenever anything queries schedules at boot, and
				// translating here trips WP 6.7's just-in-time textdomain
				// notice. Dev-facing label (cron tooling only) — do not __().
				'display'  => 'TitanCart — Every Hour',
			];
		}
		return $schedules;
	}

}
