"""Sinks: renderers/consumers of the spens event stream.

Every session, in every mode, always installs :class:`FileSink`
(events.jsonl + atomic state.json).  ``--output`` selects only the *additional*
CLI renderer via :func:`get_sink`:

- ``tty``       -- :class:`TtySink`, the rich-rendered terminal output
                   (verbatim lines on pipes, styled + recap panel on ttys)
- ``jsonl``     -- :class:`JsonSink`, one JSON object per line on stdout,
                   flushed per event
- ``background``-- no CLI renderer at all (None)
"""

from __future__ import annotations

from spens.events import Sink  # re-exported for convenience
from spens.sinks.file import FileSink
from spens.sinks.jsonl import JsonSink
from spens.sinks.tty import TtySink

__all__ = ["Sink", "get_sink", "TtySink", "JsonSink", "FileSink"]

OUTPUT_MODES = ("tty", "jsonl", "background")


def get_sink(output_mode: str):
    """Return the CLI renderer sink for ``output_mode`` (None for background)."""
    if output_mode == "tty":
        return TtySink()
    if output_mode == "jsonl":
        return JsonSink()
    if output_mode == "background":
        return None
    raise ValueError(
        f"unknown output mode '{output_mode}' (expected one of {', '.join(OUTPUT_MODES)})"
    )
