<?php

/**
 * Admin configuration search index — a flat list of every PeepSo config option across all tabs, for
 * the native WordPress Command Palette (⌘K). Auto-registered by 3/classes/api/api.php as
 * /peepso/v1/config_search. Admin only.
 *
 * GET  /peepso/v1/config_search           → { meta, tabs:[…], options:[{name,label,descript,tab,tab_label,group,url,…}], parents:{child:parent} }
 * GET  /peepso/v1/config_search?debug=1   → same payload, rebuilt live (bypasses the Mayfly cache)
 *
 * The full payload is fetched once by assets/js/admin/config-search.js and filtered client-side, so
 * there is no per-keystroke request. The index is built + cached by PeepSo3_Config_Index.
 */
class PeepSo3_REST_V1_Endpoint_Config_Search extends PeepSo3_REST_V1_Endpoint {

	/** GET — the config option index (cached; ?debug rebuilds live). */
	public function read(WP_REST_Request $request) {
		if (!PeepSo3_Roles::is_admin()) {
			return array('error' => 'auth');
		}

		$debug = (bool) $request->get_param('debug');

		return PeepSo3_Config_Index::get($debug);
	}

	protected function can_read() {
		return PeepSo3_Roles::is_admin();
	}
}

// EOF
