"""Composite: SignalAggregator runs multiple generators and returns SignalBundle."""

from __future__ import annotations

from pyalbedo.core.types import Signal, SignalBundle
from pyalbedo.core.window import MarketDataWindow
from pyalbedo.signals.base import SignalGenerator


class SignalAggregator(SignalGenerator):
    """
    Runs multiple generators and bundles their output.

    required_lookback = max(g.required_lookback for g in generators).
    generate(window) returns SignalBundle with symbol, timestamp, and list of
    non-None signals. No built-in weighting or final decision.
    """

    def __init__(self, generators: list[SignalGenerator]) -> None:
        if not generators:
            raise ValueError("generators must be non-empty")
        self._generators = generators

    @property
    def name(self) -> str:
        return "SignalAggregator"

    @property
    def required_lookback(self) -> int:
        return max(g.required_lookback for g in self._generators)

    def generate(self, window: MarketDataWindow) -> SignalBundle:
        signals: list[Signal] = []
        for gen in self._generators:
            s = gen.generate(window)
            if s is not None:
                signals.append(s)
        return SignalBundle(
            symbol=window.symbol,
            timestamp=window.last_timestamp,
            signals=tuple(signals),
        )
