"""Business-rule validators for the Bookmark domain."""
from __future__ import annotations

from repo_core.base.validators import BaseValidator, ValidationError


class BookmarkTargetIdValidator(BaseValidator):
    """Reject blank or overly-long ``event_id`` values.

    Usage::

        validator = BookmarkTargetIdValidator(max_length=128)
        clean = await validator.validate("  event-42  ")
    """

    def __init__(self, max_length: int = 128) -> None:
        self._max = max_length

    async def validate(self, data: str) -> str:
        value = data.strip() if isinstance(data, str) else data
        if not value:
            raise ValidationError("event_id cannot be blank.", field="event_id")
        if len(value) > self._max:
            raise ValidationError(
                f"event_id must be at most {self._max} characters, got {len(value)}.",
                field="event_id",
            )
        return value
