"""Структуры данных для описания правил поиска IOC."""

from __future__ import annotations

from dataclasses import dataclass
from typing import Callable, FrozenSet, Pattern

IndicatorFactory = Callable[[str, FrozenSet[str]], object]


@dataclass(frozen=True)
class PatternDefinition:
    """Описание отдельного регулярного правила."""

    name: str
    regex: Pattern[str]
    factory: IndicatorFactory
    kinds: FrozenSet[str]
    rearm: Callable[[str], str] = lambda value: value
    normalize: Callable[[str], str] = lambda value: value
    validator: Callable[[str], bool] | None = None

    def create_indicator(self, value: str) -> object:
        """Создать индикатор при помощи фабрики."""

        return self.factory(value, self.kinds)
