<?php
/**
 * File Path: includes/admin/tabs/imp-exp/class-mbs-tab-child-export.php
 *
 * Import / Export Tab — Export Child
 *
 * Handles XLSX catalog export and Settings JSON export.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

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

class MBS_Tab_Child_Export {

	use MBS_Ajax_Import_Export_Guard;

	/**
	 * Handle AJAX request to export the full catalog as a CSV file.
	 *
	 * Streams CSV directly -- exits on completion. Nonce and capability checks
	 * are performed by verify_import_export_request(); license gate enforced
	 * inside MBS_Exporter_CSV::download() as defense-in-depth.
	 *
	 * @return void Does not return on success -- MBS_Exporter_CSV::download() exits.
	 */
	public function handle_ajax_mbs_export_csv(): void {
		$this->verify_import_export_request();
		MBS_Exporter_CSV::download();
	}

	public function handle_ajax_mbs_export_xlsx(): void {
		$this->verify_import_export_request();

		if ( ! mbs_is_pro() ) {
			wp_send_json_error( array( 'message' => 'XLSX export requires a PRO license.' ) );
		}

		MBS_Catalog_XLSX_Exporter::download();
	}

	public function handle_ajax_mbs_export_settings(): void {
		$this->verify_import_export_request();

		MBS_Settings_Exporter::export_settings();
	}

	/**
	 * Handle AJAX request to export the full catalog + cover images as a ZIP.
	 *
	 * Nonce and capability checks run first; license gate is enforced
	 * inside MBS_Exporter_Zip::download() as defense-in-depth (GP-T-1).
	 *
	 * @return void Does not return on success -- MBS_Exporter_Zip::download() exits.
	 * @since  1.0.0
	 */
	public function handle_ajax_mbs_export_covers_zip(): void {
		$this->verify_import_export_request();

		if ( ! mbs_is_pro() ) {
			wp_send_json_error( array( 'message' => 'Catalog + Covers export requires a PRO license.' ) );
		}

		MBS_Exporter_Zip::download();
	}
}
