'POST','permission_callback'=>fn()=>$this->permission(Capabilities::MANAGE_BOOKINGS),'callback'=>fn($r)=>$this->respond(fn()=>$this->adminQuote($r))]); register_rest_route(CatalogController::REST_NAMESPACE,'/pricing/options',['methods'=>'GET','permission_callback'=>fn()=>$this->permission(Capabilities::MANAGE_PRICES),'callback'=>fn()=>$this->respond(fn()=>$this->options->get())]); } private function adminQuote(WP_REST_Request $r): array { $input=$this->body($r);$id=CatalogValidator::integer($input['booking_id']??null,'booking_id',1,PHP_INT_MAX,true);unset($input['booking_id']); return $id ? $this->management->edit($id,$input,get_current_user_id(),true) : $this->booking->quote($input,get_current_user_id(),true); } public function login(): bool|WP_Error {return is_user_logged_in() ?: new WP_Error('abece_booking_login_required',__('Log in to manage your bookings.','abece-booking'),['status'=>401]);} private function permission(string $cap):bool|WP_Error { $login=$this->login();if($login instanceof WP_Error)return $login;return current_user_can($cap) ?: new WP_Error('abece_booking_forbidden',__('You do not have permission to access this ABeCe Booking page.','abece-booking'),['status'=>403]); } private function body(WP_REST_Request $r):array { $body=$r->get_json_params();if(!is_array($body)||!is_object(json_decode($r->get_body())))throw new CatalogException('abece_booking_invalid_json',__('A JSON object is required.','abece-booking'),400);return $body; } private function respond(callable $operation):WP_REST_Response|WP_Error {try{$response=new WP_REST_Response($operation());$response->header('Cache-Control','private, no-store');return $response;}catch(CatalogException $e){return new WP_Error($e->errorCode,$e->getMessage(),['status'=>$e->status,'field'=>$e->field]+$e->details);}} }