<?php

namespace SerpIQ\Api;

use SerpIQ\Api\Controllers\Alerts_Controller;
use SerpIQ\Api\Controllers\Cannibalization_Controller;
use SerpIQ\Api\Controllers\Dashboard_Controller;
use SerpIQ\Api\Controllers\Content_Refresh_Controller;
use SerpIQ\Api\Controllers\Internal_Linking_Controller;
use SerpIQ\Api\Controllers\Decay_Controller;
use SerpIQ\Api\Controllers\Oauth_Controller;
use SerpIQ\Api\Controllers\Opportunities_Controller;
use SerpIQ\Api\Controllers\Pages_Controller;
use SerpIQ\Api\Controllers\Page_Links_Controller;
use SerpIQ\Api\Controllers\Queries_Controller;
use SerpIQ\Api\Controllers\Reports_Controller;
use SerpIQ\Api\Controllers\Question_Queries_Controller;
use SerpIQ\Api\Controllers\Sync_Controller;
use SerpIQ\Api\Controllers\Status_Controller;

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

/**
 * Registers `serpiq/v1` REST API routes.
 *
 * Policy: every route must set `permission_callback` to
 * {@see Rest_Permission::admin_rest_request} (capability + wp_rest nonce). New routes
 * must not use `__return_true` or capability-only checks without the REST nonce.
 */
final class Rest {
	private static ?Rest $instance = null;

	public static function instance(): Rest {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	public function init(): void {
		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
	}

	public function register_routes(): void {
		Status_Controller::instance()->register_routes();
		Oauth_Controller::instance()->register_routes();
		Sync_Controller::instance()->register_routes();
		Dashboard_Controller::instance()->register_routes();
		Queries_Controller::instance()->register_routes();
		Pages_Controller::instance()->register_routes();
		Page_Links_Controller::instance()->register_routes();
		Reports_Controller::instance()->register_routes();
		Opportunities_Controller::instance()->register_routes();
		Cannibalization_Controller::instance()->register_routes();
		Alerts_Controller::instance()->register_routes();
		Decay_Controller::instance()->register_routes();
		Content_Refresh_Controller::instance()->register_routes();
		Internal_Linking_Controller::instance()->register_routes();
		Question_Queries_Controller::instance()->register_routes();
	}
}

