def check_bw_unit(bw_unit: str) -> str:
    """Check if the bandwidth unit is one of "gbit" and "mbit".

    Parameters
    ----------
    bw_unit : str
        The bandwidth unit.

    Returns
    -------
    str
        The bandwidth unit changing to lowercase letters and removing extra spaces.

    Raises
    ------
    ValueError
        The bandwidth unit is invalid. Check if the value is one of "gbit" and "mbit".
    """
    bw_unit = bw_unit.lower().strip()

    if bw_unit not in ["gbit", "mbit"]:
        raise ValueError("invalid bandwidth unit")

    return bw_unit