import logging


def validate_config(config):
    """
    Validate the user's config. Any errors get logged. If there are 1 or more
    errors, False is returned.

    :param config: The configuration dictionary to validate
    :return: Whether or not the number of errors in the config was 0
    """

    expected_values = [
        'smtp_server', 'smtp_port', 'email_address', 'email_password',
        'recipients', 'downloads'
    ]
    errors = 0
    if config is None:
        logging.error("Configuration file is empty or does not exist.")
        return False

    for value in expected_values:
        if value not in config:
            logging.error("Invalid config: %s is not present." % value)
            errors += 1

    if 'downloads' in config:
        for download in config['downloads']:
            if 'url' not in download:
                logging.error("Invalid config. Download missing URL")
                errors += 1
            if 'name' not in download:
                logging.error("Invalid config. Download missing name")
                errors += 1

    if 'recipients' in config:
        if len(config['recipients']) < 1:
            logging.error("At least one recipient is required")
            errors += 1

    if 'timeout' not in config:
        logging.info("No timeout specified. 5 seconds will be selected.")
        config['timeout'] = 5

    return errors == 0