<?php
/**
 * Bulk legacy REST routes.
 *
 * @package SmartyPress_AI_Engine
 */

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

/**
 * Registers fast legacy bulk routes.
 */
class SmartyPress_AI_Content_Generator_Bulk_Legacy_Routes {

	/**
	 * REST namespace.
	 *
	 * @var string
	 */
	private $namespace = 'smartypress/v1';

	/**
	 * Register routes.
	 *
	 * @param object $bulk_generator Bulk legacy controller.
	 * @param object $permissions Permissions owner.
	 * @return void
	 */
	public function register( $bulk_generator, $permissions ) {
		$bulk_permission = array( $permissions, 'check_bulk_permissions' );

		register_rest_route(
			$this->namespace,
			'/bulk-generate',
			array(
				'methods'             => 'POST',
				'callback'            => array( $bulk_generator, 'generate_bulk_posts_endpoint' ),
				'permission_callback' => $bulk_permission,
			)
		);

		register_rest_route(
			$this->namespace,
			'/bulk-generate-single',
			array(
				'methods'             => 'POST',
				'callback'            => array( $bulk_generator, 'generate_single_post_endpoint' ),
				'permission_callback' => $bulk_permission,
			)
		);

		register_rest_route(
			$this->namespace,
			'/bulk-prompts',
			array(
				'methods'             => 'GET',
				'callback'            => array( $bulk_generator, 'get_prompts_endpoint' ),
				'permission_callback' => array( $permissions, 'check_permissions' ),
			)
		);

		register_rest_route(
			$this->namespace,
			'/bulk-jobs',
			array(
				'methods'             => 'POST',
				'callback'            => array( $bulk_generator, 'create_bulk_job_endpoint' ),
				'permission_callback' => $bulk_permission,
			)
		);

		register_rest_route(
			$this->namespace,
			'/bulk-estimate',
			array(
				'methods'             => 'POST',
				'callback'            => array( $bulk_generator, 'estimate_bulk_job_endpoint' ),
				'permission_callback' => $bulk_permission,
			)
		);

		register_rest_route(
			$this->namespace,
			'/bulk-jobs/(?P<job_id>[a-zA-Z0-9_-]+)',
			array(
				'methods'             => 'GET',
				'callback'            => array( $bulk_generator, 'get_bulk_job_endpoint' ),
				'permission_callback' => $bulk_permission,
			)
		);

		register_rest_route(
			$this->namespace,
			'/bulk-jobs/(?P<job_id>[a-zA-Z0-9_-]+)/process',
			array(
				'methods'             => 'POST',
				'callback'            => array( $bulk_generator, 'process_bulk_job_endpoint' ),
				'permission_callback' => $bulk_permission,
			)
		);

		register_rest_route(
			$this->namespace,
			'/bulk-jobs/(?P<job_id>[a-zA-Z0-9_-]+)/action',
			array(
				'methods'             => 'POST',
				'callback'            => array( $bulk_generator, 'bulk_job_action_endpoint' ),
				'permission_callback' => $bulk_permission,
			)
		);
	}
}
