import logging


def format_structure(structure, indent=4, _depth=0):
    """
    Converts a nested structure of folders into a formatted string.

    :param structure: structure to format
    :type structure: tuple(list(str), str)
    :param int indent: Number of spaces to indent each level of nesting
    :param int _depth: Current depth (USED INTERNALLY BY FUNCTION)
    :return: Formatted string of the folder structure
    :rtype: str
    """
    fmat = ""
    newline = '\n' + str(_depth * str(indent * ' '))

    if isinstance(structure, tuple):
        fmat += newline + str(structure[0])
        fmat += format_structure(structure[1], indent, _depth + 1)
    elif isinstance(structure, list):
        for item in structure:
            fmat += format_structure(item, indent, _depth)
    elif isinstance(structure, str):
        fmat += newline + structure
    else:
        logging.error("Unexpected type in folder structure for item '%s': %s",
                      str(structure), type(structure))
    return fmat