guard( 'manage_woocommerce', 'manage_options' ); if ( $check ) { return $check; } if ( ! wpc_is_module_enable( 'table_layout' ) ) { return [ 'error' => 'The Table Layout module is not enabled. Go to WpCafe → Extensions to enable it.' ]; } if ( ! class_exists( '\WpCafePro\SeatPlan\Controllers\Seat_Plan_Controller' ) ) { return [ 'error' => 'WpCafe Pro is not installed. The Table Layout feature requires WpCafe Pro.' ]; } $request = new \WP_REST_Request( 'GET', '/wpcafe/v2/seat-plans' ); if ( $branch_id > 0 ) { $request->set_param( 'branch_id', $branch_id ); } $controller = new \WpCafePro\SeatPlan\Controllers\Seat_Plan_Controller(); $data = $this->extract_response( $controller->get_items( $request ), 'Failed to retrieve table layout.' ); if ( isset( $data['error'] ) ) { return $data; } if ( $branch_id > 0 ) { return $this->shape_branch_detail( $branch_id, $data ); } return [ 'branches' => $data['items'] ?? [] ]; } /** * Shape the detailed seat plan for a single branch into an AI-friendly format. * * Strips geometry (positionX/Y, angle, scale, colors) and returns only the * fields the AI needs: label, chair count, price, and ticket type. * * @param int $branch_id Branch term ID. * @param array $data Raw data from extract_response(). * @return array */ private function shape_branch_detail( int $branch_id, array $data ): array { $tables = []; foreach ( $data['seat_plan'] ?? [] as $item ) { if ( 'table' !== ( $item['type'] ?? '' ) ) { continue; } $tables[] = [ 'label' => $item['label'] ?? $item['number'] ?? '', 'chair_count' => count( $item['chairs'] ?? [] ), 'price' => $item['price'] ?? 0, 'ticket_type' => $item['ticketType'] ?? '', ]; } return [ 'branch_id' => $branch_id, 'tables' => $tables, 'note' => 'For real-time seat availability, use wpcafe-get-reservation-availability.', ]; } }