<?php
/**
 * Registers every REST route under the backreload/v1 namespace.
 *
 * @package Backreload\Api
 */

namespace Backreload\Api;

use Backreload\Plugin;

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

class RestRouter {

	const NS = 'backreload/v1';

	private Plugin $plugin;

	public function __construct( Plugin $plugin ) {
		$this->plugin = $plugin;
	}

	public function register(): void {
		add_action( 'rest_api_init', [ $this, 'routes' ] );
	}

	public function routes(): void {
		( new BackupsController( $this->plugin ) )->register( self::NS );
		( new DestinationsController( $this->plugin ) )->register( self::NS );
		( new NotifiersController( $this->plugin ) )->register( self::NS );
		( new OauthController( $this->plugin ) )->register( self::NS );
		( new ScheduleController( $this->plugin ) )->register( self::NS );
		( new LogsController( $this->plugin ) )->register( self::NS );
		( new SettingsController( $this->plugin ) )->register( self::NS );
		( new DashboardController( $this->plugin ) )->register( self::NS );
		( new SystemController( $this->plugin ) )->register( self::NS );
		( new MaintenanceController( $this->plugin ) )->register( self::NS );
		( new MigrationController( $this->plugin ) )->register( self::NS );
	}

	public static function check_permissions(): bool {
		return current_user_can( 'manage_options' );
	}
}
