<?php
/**
 * Single generation REST routes.
 *
 * @package SmartyPress_AI_Engine
 */

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

/**
 * Registers single post and single plan routes.
 */
class SmartyPress_AI_Content_Generator_Single_Generation_Routes {

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

	/**
	 * Register routes.
	 *
	 * @param SmartyPress_AI_Single_Post_Generator $single_generator Single generator.
	 * @param object                               $permissions Permissions owner.
	 * @return void
	 */
	public function register( SmartyPress_AI_Single_Post_Generator $single_generator, $permissions ) {
		$routes = array(
			'/generate-single-post'          => 'generate_post_endpoint',
			'/generate-post-data'            => 'generate_post_data_endpoint',
			'/create-post'                   => 'create_post_endpoint',
			'/generate-post-plan'            => 'generate_post_plan_endpoint',
			'/improve-plan-prompt-template'  => 'improve_plan_prompt_template_endpoint',
			'/apply-post-plan-instruction'   => 'apply_post_plan_instruction_endpoint',
			'/generate-draft-from-plan'      => 'generate_draft_from_plan_endpoint',
			'/generate-title'                => 'generate_title_endpoint',
			'/generate-content'              => 'generate_content_endpoint',
			'/generate-excerpt'              => 'generate_excerpt_endpoint',
			'/generate-categories'           => 'generate_categories_endpoint',
			'/wand'                          => 'wand_endpoint',
			'/generate-sections'             => 'generate_sections_endpoint',
			'/generate-content-with-sections' => 'generate_content_with_sections_endpoint',
			'/generate-title-with-prompt'    => 'generate_title_with_prompt_endpoint',
			'/generate-excerpt-with-prompt'  => 'generate_excerpt_with_prompt_endpoint',
			'/generate-full-post'            => 'generate_full_post_endpoint',
		);

		foreach ( $routes as $route => $callback ) {
			register_rest_route(
				$this->namespace,
				$route,
				array(
					'methods'             => 'POST',
					'callback'            => array( $single_generator, $callback ),
					'permission_callback' => array( $permissions, 'check_permissions' ),
				)
			);
		}
	}
}
