# utilities/ids.py
from typing import Optional
import secrets
import string

_ALPHABET = string.ascii_uppercase + string.digits

def make_provider_txn_id(prefix: str = "VP", max_len: int = 10) -> str:
    """
    Generate an uppercase [A-Z0-9] id, length <= max_len.
    Example: 'VP' + 8 random chars -> total 10.
    """
    prefix = (prefix or "").upper()
    if max_len <= len(prefix):
        return prefix[:max_len]
    need = max_len - len(prefix)
    suffix = "".join(secrets.choice(_ALPHABET) for _ in range(need))
    return (prefix + suffix)[:max_len]
