<?php
/**
 * Auto Attribute Mapping 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\Auto_Attribute_Mapping_Rest_Controller;

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

/**
 * Class Auto_Attribute_Mapping_APIs
 *
 * Registers all Auto Attribute Mapping REST API controllers and routes
 */
class Auto_Attribute_Mapping_APIs {

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

		// Get array and object attributes.
		register_rest_route(
			Constants::REST_API_NAMESPACE,
			'/connections/(?P<connection_uuid>[a-zA-Z0-9-]+)/auto-attribute-mapping/array-object-attributes',
			array(
				array(
					'methods'             => WP_REST_Server::EDITABLE,
					'callback'            => array( $controller, 'get_array_object_attributes' ),
					'permission_callback' => array( $controller, 'check_permissions' ),
				),
			)
		);

		// Get variable attributes.
		register_rest_route(
			Constants::REST_API_NAMESPACE,
			'/connections/(?P<connection_uuid>[a-zA-Z0-9-]+)/auto-attribute-mapping/variable-attributes',
			array(
				array(
					'methods'             => WP_REST_Server::READABLE,
					'callback'            => array( $controller, 'get_variable_attributes' ),
					'permission_callback' => array( $controller, 'check_permissions' ),
				),
			)
		);

		// Get child attributes.
		register_rest_route(
			Constants::REST_API_NAMESPACE,
			'/connections/(?P<connection_uuid>[a-zA-Z0-9-]+)/auto-attribute-mapping/child-attributes',
			array(
				array(
					'methods'             => WP_REST_Server::EDITABLE,
					'callback'            => array( $controller, 'get_child_attributes' ),
					'permission_callback' => array( $controller, 'check_permissions' ),
				),
			)
		);
	}
}
