from collections.abc import Callable, Iterable
from dataclasses import dataclass
from typing import Generic, TypeVar

P = TypeVar("P")
R = TypeVar("R")
S = TypeVar("S")
M = TypeVar("M")


@dataclass(frozen=True)
class PassSpec(Generic[P, S]):
    name: str
    run: Callable[[P, S], None]
    when: Callable[[P, S], bool] | None = None


@dataclass(frozen=True)
class ForEachModule(Generic[P, S, M]):
    name: str
    modules: Callable[[P, S], Iterable[M]]
    body: tuple[PassSpec[P, M], ...]


@dataclass(frozen=True)
class Segment(Generic[P, R, S]):
    name: str
    view: Callable[[R], S]
    steps: tuple[PassSpec[P, S], ...]
