route('/admin/tools/onboarding','GET',fn()=>$this->service->onboarding()); $this->route('/admin/tools/onboarding','PATCH',fn($r)=>$this->service->dismiss($this->body($r))); $this->route('/admin/tools/booking-page','POST',fn($r)=>$this->service->createPage($this->body($r))); $this->route('/admin/tools/status','GET',fn()=>$this->service->status()); $this->route('/admin/tools/test-email','POST',fn($r)=>$this->service->testEmail($this->body($r))); $this->route('/admin/tools/data','DELETE',fn($r)=>$this->service->deleteData($this->body($r))); } private function route(string $path,string $methods,callable $operation): void { register_rest_route(CatalogController::REST_NAMESPACE,$path,['methods'=>$methods,'permission_callback'=>static fn()=>current_user_can('manage_options')?:new \WP_Error('abece_booking_forbidden',__('You do not have permission to use these tools.','abece-booking'),['status'=>rest_authorization_required_code()]),'callback'=>function($r)use($operation){try{return new \WP_REST_Response($operation($r),200,['Cache-Control'=>'private, no-store','Vary'=>'Cookie']);}catch(CatalogException $e){return new \WP_Error($e->errorCode,$e->getMessage(),['status'=>$e->status,'field'=>$e->field]);}}]); } private function body(\WP_REST_Request $r): array {if(!is_object(json_decode($r->get_body())))throw new CatalogException('abece_booking_invalid_json',__('A JSON object is required.','abece-booking'),400);return $r->get_json_params();} }