from __future__ import annotations

import re

_SLUG_RE = re.compile(r"[^a-z0-9]+")


class AdminConflictError(ValueError):
    pass


class AdminValidationError(ValueError):
    pass


def slugify(value: str) -> str:
    slug = _SLUG_RE.sub("-", value.strip().casefold()).strip("-")
    if not slug:
        raise AdminValidationError("A slug must contain at least one letter or number.")
    return slug[:100]

