"""Auto-generated by adk-fluent generator. Manual edits will be overwritten."""

from __future__ import annotations

from collections import defaultdict
from collections.abc import Callable
from typing import TYPE_CHECKING, Any, Self

from google.adk.agents import SequentialAgent

from adk_fluent._base import BuilderBase

if TYPE_CHECKING:
    from google.adk.agents.base_agent import BaseAgent


class Pipeline(BuilderBase):
    """Run sub-agents sequentially."""

    _ALIASES: dict[str, str] = {}
    _CALLBACK_ALIASES: dict[str, str] = {}
    _ADDITIVE_FIELDS: set[str] = set()
    _ADK_TARGET_CLASS = SequentialAgent

    def __init__(self, name: str) -> None:
        self._config: dict[str, Any] = {"name": name}
        self._callbacks: dict[str, list[Callable]] = defaultdict(list)
        self._lists: dict[str, list] = defaultdict(list)
        self._frozen = False

    def sub_agents(self, value: list[BaseAgent]) -> Self:
        """Set the ``sub_agents`` field."""
        self = self._maybe_fork_for_mutation()
        self._config["sub_agents"] = value
        return self

    def step(self, value: BaseAgent) -> Self:
        """Append to ``sub_agents`` (lazy — built at .build() time)."""
        self = self._maybe_fork_for_mutation()
        self._lists["sub_agents"].append(value)
        return self

    def sub_agent(self, value: BaseAgent) -> Self:
        """Append to ``sub_agents`` (lazy — built at .build() time)."""
        self = self._maybe_fork_for_mutation()
        self._lists["sub_agents"].append(value)
        return self

    def build(self) -> SequentialAgent:
        """Run sub-agents sequentially. Resolve into a native ADK SequentialAgent."""
        config = self._prepare_build_config()
        result = self._safe_build(SequentialAgent, config)
        return self._apply_native_hooks(result)
