from __future__ import annotations

from dataclasses import dataclass
from typing import Iterable, List


class ValidationError(ValueError):
    pass


@dataclass
class ErrorCollector:
    error_separator: str = "; "
    error_limit: int = 10

    def __post_init__(self) -> None:
        self._errors: List[str] = []

    @property
    def errors(self) -> List[str]:
        return list(self._errors)

    def add(self, message: str) -> None:
        self._errors.append(message)

    def extend(self, messages: Iterable[str]) -> None:
        self._errors.extend(list(messages))

    def raise_if_any(self) -> None:
        if not self._errors:
            return

        limit = min(len(self._errors), self.error_limit)
        msg = self.error_separator.join(self._errors[:limit])
        raise ValidationError(msg)
