from typing import Optional

def program(*args) -> str:
    """This is used for generating a block of code that is separated by newlines.

    Returns:
        str: The output code
    """

    return '\n'.join(args)


def create_func(name: str, args: str, body: str) -> str:
    """Creates the code for a python function.

    Args:
        name (str): The name of the function
        args (str): The args that the function takes, separated by commas
        body (str): The body of the function, usually generated by program()

    Returns:
        str: The function code
    """

    return f'''def {name}({args}):
{indent(body)}
'''


def create_class(name: str, body: str, extends: Optional[str] = None) -> str:
    """Creates a class function with the given name and body.

    Args:
        name (str): The name of the class
        body (str): The body of the class, usually generated by program()
        extends (Optional[str], optional): The class that this class extends. Defaults to None.

    Returns:
        str: The code for the class
    """

    return f'''
class {name}{f"({extends})" if extends else ""}:
{indent(body)}
'''


def indent(text: str, indentation: str = '    ') -> str:
    """Indents the provided text to a specific amount of spaces.

    Args:
        text (str): The code to be indented
        indentation (str, optional): The indentation value to be used. Defaults to '    '.

    Returns:
        str: The returned code
    """

    return '\n'.join(indentation + line for line in text.splitlines())
