"""Public-facing identifier minting for SME-Hub calls and applications.

SP2 mints application IDs as ``INC-<8 hex>`` directly inside ``Application.save``.
SP4 / SP5 currently do their own thing. This helper centralises the format so
all SPs converge once they migrate.

Format: ``<PREFIX>-<8 uppercase hex>``. The 8-char suffix gives 16^8 ≈ 4.3B
distinct values per prefix — easily room for a decade of RUFORUM cohorts
without collision risk.
"""
from __future__ import annotations

import uuid


def _short_hex() -> str:
    return uuid.uuid4().hex[:8].upper()


def generate_application_id(prefix: str) -> str:
    """Return ``f"{PREFIX}-XXXXXXXX"`` for a new application record.

    Suggested prefixes:
        ``INC`` — incubation programme application (SP2)
        ``ISD`` — innovation showcasing / challenge application (SP4)
        ``INV`` — funding application (SP5)
    """
    if not prefix or not prefix.isalpha():
        raise ValueError("prefix must be a non-empty alphabetical token")
    return f"{prefix.upper()}-{_short_hex()}"


def generate_call_id(prefix: str) -> str:
    """Return ``f"{PREFIX}-CALL-XXXXXXXX"`` for a new call/programme record."""
    if not prefix or not prefix.isalpha():
        raise ValueError("prefix must be a non-empty alphabetical token")
    return f"{prefix.upper()}-CALL-{_short_hex()}"
