<?php
/**
 * Plugin Utility REST API Loader
 *
 * @category   WordPress_Plugin
 * @package    Common
 * @subpackage Rest_APIs
 * @author     miniOrange <info@miniorange.com>
 * @license    miniOrange
 * @link       https://plugins.miniorange.com
 */

namespace MOWCPS\Common\Rest_APIs;

use WP_REST_Server;
use MOWCPS\Common\Constants\Constants;
use MOWCPS\Common\Controllers\Rest_API\Plugin_Utility_Rest_Controller;

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

/**
 * Class Plugin_Utility_APIs
 *
 * Registers plugin utility REST API routes
 */
class Plugin_Utility_APIs {

	/**
	 * Register all routes
	 *
	 * @return void
	 */
	public static function register_routes() {
		$controller = new Plugin_Utility_Rest_Controller();

		// Check plugin status.
		register_rest_route(
			Constants::REST_API_NAMESPACE,
			'/plugins/check',
			array(
				'methods'             => WP_REST_Server::READABLE,
				'callback'            => array( $controller, 'check_plugin' ),
				'permission_callback' => array( $controller, 'check_permissions' ),
			)
		);

		// Activate plugin.
		register_rest_route(
			Constants::REST_API_NAMESPACE,
			'/plugins/activate',
			array(
				'methods'             => WP_REST_Server::CREATABLE,
				'callback'            => array( $controller, 'activate_plugin' ),
				'permission_callback' => array( $controller, 'check_permissions' ),
			)
		);

		// Install and activate plugin.
		register_rest_route(
			Constants::REST_API_NAMESPACE,
			'/plugins/install',
			array(
				'methods'             => WP_REST_Server::CREATABLE,
				'callback'            => array( $controller, 'install_plugin' ),
				'permission_callback' => array( $controller, 'check_permissions' ),
			)
		);
	}
}
