import textwrap


def build_raw_influx_query(field, measurement, function, filters, group_by_time="$__interval", fill="null") -> str:
    """
    Build a raw InfluxDB query.
    """
    copied_filters = filters.copy()
    copied_filters.append("$timeFilter")
    string_filters = " AND ".join(copied_filters)
    query = f"""
    SELECT {function}("{field}")
    FROM "{measurement}"
    WHERE {string_filters} GROUP BY time({group_by_time}) fill({fill})
    """

    return textwrap.dedent(query).replace("\n", " ").strip()