def indent_sql(query: str) -> str:
    """ Indents an SQL query based on opening and closing brackets.
    """

    indent = 0
    lines = query.split("\n")
    for idx, line in enumerate(lines):
        lines[idx] = (" " * indent) + line
        if len(line) >= 1:
            if line[-1] == "(":
                indent += 4
            elif line[-1] == ")":
                indent -= 4
    return "\n".join(lines)