import re
from abc import ABC, abstractmethod

from probegpt.core.models import Probe

# Matches a line that is exactly "---" (with optional surrounding whitespace/newlines)
_SEP_RE = re.compile(r"\n[ \t]*---[ \t]*\n|^[ \t]*---[ \t]*\n|\n[ \t]*---[ \t]*$", re.MULTILINE)


class AbstractStrategy(ABC):
    @abstractmethod
    def generate(
        self,
        seeds: list[Probe],
        model: object,
        count: int = 5,
        **kwargs: object,
    ) -> list[str]:
        """Generate probe prompt strings."""
        ...

    @abstractmethod
    def get_name(self) -> str:
        """Short identifier for this strategy."""
        ...

    @abstractmethod
    def get_description(self) -> str:
        """One-line description of what this strategy does."""
        ...

    def _parse_candidates(self, text: str) -> list[str]:
        """Split LLM output on '---' separator lines into individual probe strings."""
        parts = _SEP_RE.split(text)
        results = []
        for part in parts:
            cleaned = part.strip()
            if cleaned and not re.fullmatch(r"-+", cleaned):
                results.append(cleaned)
        return results
