"""Pre-generation hook for the fullstack cookiecutter template.

Validates that ``project_name`` is a valid Python identifier so the
generated package dir + imports (``from <project_name>.X import Y``) do
not raise ``SyntaxError``. Hyphens, dots, spaces and leading digits are
rejected with a hint to use an underscore-separated name instead.

See issue #262: default ``my-fullstack`` used to render as
``from my-fullstack.config.settings import settings`` which is a
``SyntaxError`` (``-`` is not allowed in a Python identifier).
"""

from __future__ import annotations

import re
import sys

_VALID_IDENTIFIER = re.compile(r"^[a-z][a-z0-9_]*$")


def main() -> None:
    project_name = "{{ cookiecutter.project_name }}"
    if not _VALID_IDENTIFIER.fullmatch(project_name):
        sys.exit(
            f"Invalid project_name: {project_name!r}\n"
            "project_name must be a valid Python identifier matching "
            "^[a-z][a-z0-9_]*$ (lowercase, no hyphens/dots/spaces, "
            "no leading digit).\n"
            f"Use 'my_fullstack' instead of 'my-fullstack' (or 'my.fullstack', "
            "'my fullstack')."
        )


if __name__ == "__main__":
    main()