def fetch_and_download_files()

in build.py [0:0]


def fetch_and_download_files(kibana_version, integrations_dir, total_files):
    """Fetch and download files based on the Kibana version, logging the total files count."""
    url = f"https://epr.elastic.co/search?kibana.version={kibana_version}"
    session = setup_download_session()
    response = session.get(url)
    response.raise_for_status()
    packages = response.json()
    
    downloaded_count = 0
    expected_files = []
    with ThreadPoolExecutor(max_workers=10) as executor:
        future_to_file = {}
        for pkg in packages:
            base_url = "https://epr.elastic.co"
            file_path = integrations_dir / Path(pkg['download']).name
            signature_path = integrations_dir / Path(pkg['signature_path']).name
            
            expected_files.append(file_path)
            expected_files.append(signature_path)

            future_to_file[executor.submit(download_file, session, base_url + pkg['download'], file_path)] = file_path
            future_to_file[executor.submit(download_file, session, base_url + pkg['signature_path'], signature_path)] = signature_path

        for future in as_completed(future_to_file):
            path = future_to_file[future]
            try:
                result = future.result()
                if result:
                    downloaded_count += 1
                    logging.info(f"Downloaded: ({downloaded_count} of {total_files}) {path.name}")
            except Exception as e:
                logging.error(f"File download failed for {path.name}: {e}")

    verify_downloaded_files(integrations_dir, expected_files)