import sys


# Script for Claude to run to determine whether a PDF has fillable form fields. See forms.md.


def has_fillable_fields(pdf_path: str) -> bool:
    try:
        from pypdf import PdfReader
    except ModuleNotFoundError as exc:
        raise RuntimeError("Missing dependency: pypdf") from exc

    reader = PdfReader(pdf_path)
    return bool(reader.get_fields())


def main(argv: list[str] | None = None) -> int:
    args = argv if argv is not None else sys.argv[1:]
    if len(args) != 1:
        print("Usage: check_fillable_fields.py [input pdf]")
        return 1

    try:
        if has_fillable_fields(args[0]):
            print("This PDF has fillable form fields")
        else:
            print("This PDF does not have fillable form fields; you will need to visually determine where to enter data")
        return 0
    except RuntimeError as exc:
        print(str(exc), file=sys.stderr)
        return 1


if __name__ == "__main__":
    raise SystemExit(main())
