#!/usr/bin/env python3
"""
Parse the reserved names data into a Python set.
"""

from datetime import UTC, datetime
from pathlib import Path
from sys import stdout
import json

lists = {
    "ALL": "source_data/reserved-names.json",
}


def parse_list(set_name, filename):
    """
    Parse data from a given file into a Python set with the given name.
    """
    contents = json.loads(Path(filename).read_text())

    return "{}: set[str] = {{\n{}}}".format(
        set_name,
        "".join(f'    "{each.rstrip()}",\n' for each in contents),
    )


DOCSTRING = f'''\
"""
A collection of reserved names used by GitHub which are not real users.

The source of this data is the npm github-reserved-names project which lives
at https://npm.im/github-reserved-names.
"""

# Autogenerated on {datetime.now(UTC).isoformat()}.
# Don't edit this file directly, it's generated by `bin/parse_source_data`.

'''

stdout.write(DOCSTRING)
stdout.write(
    "\n\n".join([parse_list(*args) for args in sorted(lists.items())]),
)
stdout.write("\n")
