"""Tarot word namespace - fluent cipher operations."""

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from tarot.card.data import CardDataLoader


class _Word:
    """Fluent accessor for word analysis and cipher operations."""

    _loader: "CardDataLoader | None" = None
    _initialized: bool = False

    @classmethod
    def _ensure_initialized(cls) -> None:
        """Lazy-load CardDataLoader on first access."""
        if cls._initialized:
            return

        from tarot.card.data import CardDataLoader

        cls._loader = CardDataLoader()
        cls._initialized = True

    @classmethod
    def word(cls, text: str, *, alphabet: str = "english"):
        """
        Start a fluent cipher request for the given text.

        Usage:
            word.word('MAGICK').cipher('english_simple')
            word.word('MAGICK', alphabet='hebrew').cipher('hebrew_standard')
        """
        cls._ensure_initialized()
        assert cls._loader is not None, "Loader not initialized"
        return cls._loader.word(text, alphabet=alphabet)


# Create singleton instance
word = _Word()
