import logging


def apply_white_black_lists(features, white_list=None, black_list=None):
    """Helper to select features based on white and/or black list

    Parameters
    ----------
    features: dict
        Dictionary of track feature metrics to be filtered
    white_list: list or None
        List of feature names to use. If specified features not in white_list
        will be thrown away. Do not specify if specifying `black_list`.
    black_list: list or None
        List of features names to exclude. If specified, all features that do
        not appear in this list will be used. Do not specify if specifying
        `white_list`.

    Returns
    -------
    filtered_features: dict
        Dictionary of same feature values but reduced depending on specification
        of `white_list` or `black_list`
    """

    # Throw warning if we see both lists
    if white_list and black_list:
        logging.warning('Feature white_list and black_list were specified. Using only white_list.')

    if white_list:
        features_filtered = {feat:val for feat, val in features.items()
                             if feat in white_list}
        return features_filtered

    if black_list:
        features_filtered = {feat:val for feat, val in features.items()
                             if feat not in black_list}
        return features_filtered

    # If neither existed, return features
    return features