import re


def create_file_name(document_tracking_id, valid_output):
    """
    Returns filename according to standard:
    https://docs.oasis-open.org/csaf/csaf/v2.0/csd01/csaf-v2.0-csd01.html#51-filename
    if valid_input is false, `_invalid ` is appended to filename.
    """
    if document_tracking_id is not None:
        file_name = re.sub(r"([^+\-_a-z0-9]+)", '_', document_tracking_id.lower())
    else:
        file_name = 'out'

    if not valid_output:
        file_name = f'{file_name}_invalid'
    file_name = f'{file_name}.json'
    return file_name