"""
Module which executes whole component
"""

from shadowserver_module.Download import current_day_scan
from shadowserver_module.Remove import remove_csv_after, remove_csv_before
from shadowserver_module.Neo4j import prepare_json
import structlog


def process_vulnerabilities(path, ss_user, ss_password, import_path, name, logger=structlog.get_logger()):
    """
    Calls functions for downloading and parsing vulnerabilities as well as creating json file.
    :param path: path where CSVs will be downloaded
    :param ss_user: Shadowserver username
    :param ss_password: Shadowserver password
    :param import_path: path where json will be stored
    :param name: name of json file
    :param logger: logger for the method
    :return: Statistics about parsed vulnerabilities
    """
    logger.info("Component started")
    if current_day_scan(path, ss_user, ss_password, logger):
        remove_csv_before(path, logger)
        stats = prepare_json(path, import_path, name, logger)
        remove_csv_after(path, logger)
        logger.info("JSON sucessfully created")
        return stats
    return "No vulnerabilities found"
