<?php
/**
 * Authorization REST API Loader
 *
 * @category   WordPress_Plugin
 * @package    Common
 * @subpackage Rest_APIs
 * @author     miniOrange <info@miniorange.com>
 * @license    MIT/Expat
 * @link       https://plugins.miniorange.com/woocommerce-api-product-sync-with-woocommerce-rest-apis
 */

namespace MOWCPS\Common\Rest_APIs;

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

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

/**
 * Class Authorization_APIs
 *
 * Registers all Authorization REST API controllers and routes
 */
class Authorization_APIs {

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

		register_rest_route(
			Constants::REST_API_NAMESPACE,
			'/suppliers/(?P<supplier_uuid>[a-zA-Z0-9-]+)/authorization',
			array(
				array(
					'methods'             => WP_REST_Server::READABLE,
					'callback'            => array( $controller, 'get_item' ),
					'permission_callback' => array( $controller, 'check_permissions' ),
				),
				array(
					'methods'             => WP_REST_Server::CREATABLE,
					'callback'            => array( $controller, 'create_item' ),
					'permission_callback' => array( $controller, 'check_permissions' ),
				),
				array(
					'methods'             => WP_REST_Server::EDITABLE,
					'callback'            => array( $controller, 'update_item' ),
					'permission_callback' => array( $controller, 'check_permissions' ),
				),
			)
		);
	}
}
