/**
 * Function to find a specific document based on its ID in a nested tuple structure.
 *
 * @param nestedTuples A nested tuple representing the document hierarchy.
 * @param documentId The ID of the document to be found.
 * @return A tuple containing the path to the document and its index at the final level.
 *
 * Example:
 * For nestedTuples = (('Folder A', (('Subfolder 1', (1, 2, 3)), ('Subfolder 2', (4, 5, 6))),
 *                    ('Folder B', (('Subfolder 3', (7, 8, 9)), ('Subfolder 4', (10, 11, 12))))
 *
 * findDocument(nestedTuples, 9) -> (('Folder B', 'Subfolder 3'), 2)
 */
fun findDocument(nestedTuples: List<Any>, documentId: Int): Pair<List<String>, Int> {

    val stack = mutableListOf<Pair<List<Any>, List<String>>>()
    stack.add(Pair(nestedTuples, emptyList()))

    while (stack.isNotEmpty()) {
        val (currentTuple, path) = stack.removeAt(stack.size - 1)

        for (i in currentTuple.indices) {
            val item = currentTuple[i]
            if (item is Int && item == documentId) {
                return Pair(path, i)
            }

            if (item is List<*>) {
                stack.add(Pair(item as List<Any>, path + listOf(i.toString())))
            }
        }
    }

    return Pair(emptyList(), -1)
}
/**
 * Function to find a specific document based on its ID in a nested tuple structure.
 *
 * @param nestedTuples A nested tuple representing the document hierarchy.
 * @param documentId The ID of the document to be found.
 * @return A tuple containing the path to the document and its index at the final level.
 *
 * Example:
 * For nestedTuples = (('Folder A', (('Subfolder 1', (1, 2, 3)), ('Subfolder 2', (4, 5, 6))),
 *                    ('Folder B', (('Subfolder 3', (7, 8, 9)), ('Subfolder 4', (10, 11, 12))))
 *
 * findDocument(nestedTuples, 9) -> (('Folder B', 'Subfolder 3'), 2)
 */
fun findDocument(nestedTuples: List<Any>, documentId: Int): Pair<List<String>, Int> {
/**
 * Function to find a specific document based on its ID in a nested tuple structure.
 *
 * @param nestedTuples A nested tuple representing the document hierarchy.
 * @param documentId The ID of the document to be found.
 * @return A tuple containing the path to the document and its index at the final level.
 *
 * Example:
 * For nestedTuples = (('Folder A', (('Subfolder 1', (1, 2, 3)), ('Subfolder 2', (4, 5, 6))),
 *                    ('Folder B', (('Subfolder 3', (7, 8, 9)), ('Subfolder 4', (10, 11, 12))))
 *
 * findDocument(nestedTuples, 9) -> (('Folder B', 'Subfolder 3'), 2)
 */
fun findDocument(nestedTuples: List<Any>, documentId: Int): Pair<List<String>, Int> {

    val stack = mutableListOf<Pair<List<Any>, List<String>>>()
    stack.add(Pair(nestedTuples, emptyList()))

    while (stack.isNotEmpty()) {
        val (currentTuple, path) = stack.removeAt(stack.size - 1)

        for (i in currentTuple.indices) {
            val item = currentTuple[i]
            if (item is Int && item == documentId) {
                return Pair(path, i)
            }

            if (item is List<*>) {
                stack.add(Pair(item as List<Any>, path + listOf(i.toString())))
            }
        }
    }

    return Pair(emptyList(), -1)
}