#!/usr/bin/env python3
"""Download all paper data for every author listed in authors.txt.\n
Runs in three phases:\n
1. Download (or refresh) BibTeX for each author from INSPIRE-HEP.
2. Merge all author BibTeX entries in memory and extract arXiv IDs.
3. Download full paper data (PDF, abstract, BibTeX, references, citations)
   for each arXiv ID.\n
Existing files are skipped unless ``--force`` is given.\n
Options:
    --force   Re-download all files even if they already exist.\n
Usage:
    python scripts/download_all_author_papers.py
    python scripts/download_all_author_papers.py --force
"""

import argparse
import os
import sys

sys.path.insert(0, os.path.dirname(__file__))

from action_lib import download_all_author_papers

def main() -> None:
    """Parse CLI arguments and run the three-phase download pipeline."""
    parser = argparse.ArgumentParser(
        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
    )
    parser.add_argument(
        "--force",
        action="store_true",
        help="Re-download all files even if they already exist",
    )
    args = parser.parse_args()
    download_all_author_papers(force=args.force)

if __name__ == "__main__":
    main()
