from pathlib import Path
from typing import Set
import logging


def has_required_files(folder: Path, data_adj: str, required: Set[str]) -> bool:
    """
    :param folder: a path to look for files in
    :param data_adj: an adjective to use in logging lines
    :param required: names of files to look for in folder
    :return: True if folder exists, and either (1) required is empty, or (2)
    folder contains one or more members of required. In the latter case, those members
    are removed from required.
    """
    if not folder.is_dir():
        logging.info(f"Not found: {data_adj} folder {folder}")
        return False
    files_found = [path.name for path in folder.glob("*.csv")]
    if required and not files_found:
        logging.info(f"Found, but empty: {data_adj} folder {folder}")
        return False
    found = required.intersection(files_found)
    logging.info(f"Found {len(found)} of {len(required)} files in: {data_adj} folder {folder}")
    if found or not required:
        required.difference_update(found)
        return True
    return False