def filter_services(api_model, services=frozenset(), excluded_services=frozenset()):
    """Build a list of services by merging together a white- and black-list.

    :param dict api_model: the reference API model
    :param frozenset services: services to include
    :param frozenset excluded_services: services to exclude
    :rtype: frozenset
    :return: the list of merged services
    """
    available = frozenset(list(api_model.keys()))
    if services:
        invalid = services - available
        if invalid:
            raise ValueError('Invalid requested service(s): {}'.format(invalid))
        enabled = services
    else:
        enabled = available

    if excluded_services:
        invalid = excluded_services - available
        if invalid:
            raise ValueError('Invalid excluded service(s): {}'.format(invalid))
        enabled = enabled - excluded_services

    return enabled