"""Shared text helpers used across all generated domains."""
from __future__ import annotations


def slugify(text: str) -> str:
    """Lowercase, spaces to hyphens, strip non-alphanumerics."""
    out = []
    for ch in text.lower().strip():
        if ch.isalnum():
            out.append(ch)
        elif ch in (" ", "-", "_"):
            out.append("-")
    slug = "".join(out)
    while "--" in slug:
        slug = slug.replace("--", "-")
    return slug.strip("-")


def label(domain: str, name: str, index: int) -> str:
    """Canonical display label for a generated record."""
    return f"{domain}:{name}#{index:04d}"
