from typing import Iterable


def build_query_string(
    metadata: bool,
    features: Iterable[str],
    api_key: str,
    longitude: float,
    latitude: float,
    **extra_parameters,
) -> str:
    """Builds an API query string for BreezoMeter"""
    query = extra_parameters
    query.update(
        {
            "metadata": "true" if metadata else "false",
            "key": api_key,
            "lat": latitude,
            "lon": longitude,
        }
    )
    if features:
        query.update({"features": ",".join(features)})

    return "&".join(
        ["{}={}".format(key, value) for key, value in sorted(query.items())]
    )