from typing import Union


def invalid_output(
        query: dict, db_query: Union[str, dict], api_key: str, error: str, start_record: int,
        page_length: int) -> dict:
    """Create and return the output for a failed request.

    Args:
        query: The query in format as defined in wrapper/input_format.py.
        db_query: The query that was sent to the API in its language.
        api_key: The key used for the request.
        error: The error message returned.
        start_record: The index of the first record requested.
        page_length: The page length requested.

    Returns:
        A dict containing the passed values and "-1" as index where necessary
        to be compliant with wrapper/output_format.
    """
    out = dict()
    out["query"] = query
    out["dbQuery"] = db_query
    out["apiKey"] = api_key
    out["error"] = error
    out["result"] = {
        "total": "-1",
        "start": str(start_record),
        "pageLength": str(page_length),
        "recordsDisplayed": "0",
    }
    out["records"] = list()

    return out