"""Container block implementation."""

from __future__ import annotations

from yera.events.blocks.base import LayoutHandle, _BlockFactory
from yera.events.blocks.exit import unsupported_block_event
from yera.events.exceptions import UnsupportedAwaitUserBlockError
from yera.events.models import ContainerData
from yera.events.stream import is_restricted_stream


class _ContainerBlockFactory(_BlockFactory):
    """Factory for container blocks."""

    def __init__(self):
        super().__init__("container")

    def __call__(self, border: bool = False) -> LayoutHandle:
        """Return a context manager for creating container layouts."""
        if is_restricted_stream():
            unsupported_block_event(self.block_type)
            raise UnsupportedAwaitUserBlockError(self.block_type)
        block_id = self._generate_block_id()
        return LayoutHandle(block_id, "container", ContainerData(showBorder=border))


# Create the container callable/context manager
container = _ContainerBlockFactory()

__all__ = ["container"]
