<?php
namespace Prodigy\includes\helpers;

/**
 * Prodigy products includes helper
 *
 * @version    3.2.0
 * @package    Prodigy
 * @subpackage Prodigy/includes
 */
class Prodigy_Includes_Helper {

	/**
	 * Organizes a list of included items by their type and ID.
	 *
	 * @param   array $included_list  A list of included items, where each item is expected to have 'type' and 'id' keys.
	 *
	 * @return array An associative array grouped by type, where each type key contains items indexed by their ID.
	 */
	public static function prepare_included_by_type( array $included_list ): array {
		$included_by_type = array();
		if ( empty( $included_list ) ) {
			return array();
		}

		foreach ( $included_list as $included ) {
			if ( ! isset( $included_by_type[ $included['type'] ] ) ) {
				$included_by_type[ $included['type'] ] = array();
			}
			$included_by_type[ $included['type'] ][ (int) $included['id'] ] = $included;
		}

		return $included_by_type;
	}
}
