<?php
/**
 * Core preparer for product categories response data for select2 fields.
 *
 * @package Ilabs\Firevert\Core\Api\Preparer
 */

declare( strict_types=1 );

namespace Ilabs\Firevert\Core\Api\Preparer;

/**
 * Class ProductsResponsePreparer
 */
final class ProductCategoriesResponsePreparer {

	/**
	 * Prepares the final frontend payload based on the product categories query result.
	 *
	 * @param array $product_categories_data Products query result.
	 *
	 * @return array<string, mixed> Final response data structure for frontend.
	 */
	public static function prepare_response( array $product_categories_data ): array {
		$results = array();

		foreach ( $product_categories_data['product_categories'] as $product ) {
			$results[] = array(
				'id'   => $product['id'],
				'name' => $product['name'],
			);
		}

		return array(
			'results'    => $results,
			'pagination' => array(
				'more'         => $product_categories_data['has_more'],
				'total_pages'  => $product_categories_data['total_pages'],
				'current_page' => $product_categories_data['current_page'],
			),
		);
	}
}
