<?php
/**
 * REST API route registration.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Rest;

/**
 * Registers versioned JJ\'s Post Scheduler REST routes.
 */
final class RestServiceProvider {
	private ?LaunchesController $launches;
	private ?SystemStatusController $system_status;
	private ?RecordingsController $recordings;
	/**
	 * Creates the REST service provider.
	 *
	 * @param LaunchesController|null     $launches Launch REST controller.
	 * @param SystemStatusController|null $system_status System status REST controller.
	 * @param RecordingsController|null   $recordings Recording REST controller.
	 */
	public function __construct( ?LaunchesController $launches = null, ?SystemStatusController $system_status = null, ?RecordingsController $recordings = null ) {
		$this->launches      = $launches;
		$this->system_status = $system_status;
		$this->recordings    = $recordings;
	}

	/**
	 * Hooks route registration into WordPress.
	 */
	public function register(): void {
		add_action( 'rest_api_init', array( $this, 'registerRoutes' ) );
	}

	/**
	 * Registers all REST controller routes.
	 */
	public function registerRoutes(): void {
		if ( null !== $this->launches ) {
			$this->launches->registerRoutes();
		}
		if ( null !== $this->system_status ) {
			$this->system_status->registerRoutes();
		}

		if ( null !== $this->recordings ) {
			$this->recordings->registerRoutes();
		}
	}
}
