"""
Tool Operators

This module contains domain-specific tool operators:
- Search tools (web search, document search)
- Data extraction tools

These operators inherit from base operator classes in sage.kernel.operators
and implement tool-specific business logic.

.. deprecated::
   ``ArxivPaperSearcher``, ``ArxivSearcher``, ``DuckDuckGoSearcher``,
   ``NatureNewsFetcherTool``, ``URLTextExtractorTool``, ``ImageCaptioner``, and
   ``TextDetector`` have been moved to the ``isage-tools`` package.
   Import them from ``sage.tools`` instead::

       from sage.tools import ArxivSearcher, DuckDuckGoSearcher

   Install: ``pip install isage-tools`` or ``pip install isage-middleware[capability-tools]``

Note: ``BochaSearchTool`` / ``EnhancedBochaSearchTool`` remain here because they
      depend on ``sage.middleware.operators.context`` types.
"""

import warnings

# BochaSearchTool stays in middleware — depends on middleware context types.
from sage.middleware.operators.tools.searcher_tool import BochaSearchTool

# ── Tools extracted to isage-tools ──────────────────────────────────────────
# Try importing from the canonical new location first.
# If isage-tools is not installed, fall back to local copies with a visible
# deprecation warning so users know to install the extra.
try:
    from sage.tools import (
        ArxivPaperSearcher,  # canonical
        ArxivSearcher,  # canonical
        DuckDuckGoSearcher,  # canonical
        NatureNewsFetcherTool,  # canonical
        URLTextExtractorTool,  # canonical
    )

    # Backward-compat aliases expected by old code
    from sage.tools.arxiv_paper_searcher import _Searcher_Tool
    from sage.tools.nature_news_fetcher import Nature_News_Fetcher_Tool
    from sage.tools.url_text_extractor import URL_Text_Extractor_Tool

except ImportError:
    warnings.warn(
        "isage-tools is not installed. "
        "Search/scraping tools (ArxivSearcher, DuckDuckGoSearcher, etc.) are "
        "unavailable. Install with: pip install isage-tools  or  "
        "pip install isage-middleware[capability-tools]",
        ImportWarning,
        stacklevel=2,
    )
    # Fall back to local implementations (kept for backward compat).
    from sage.middleware.operators.tools.arxiv_paper_searcher import (  # noqa: F401
        _Searcher_Tool,
    )
    from sage.middleware.operators.tools.arxiv_searcher import (  # noqa: F401
        ArxivSearcher,
    )
    from sage.middleware.operators.tools.nature_news_fetcher import (  # noqa: F401
        Nature_News_Fetcher_Tool,
        NatureNewsFetcherTool,
    )
    from sage.middleware.operators.tools.url_text_extractor import (  # noqa: F401
        URL_Text_Extractor_Tool,
        URLTextExtractorTool,
    )

    ArxivPaperSearcher = _Searcher_Tool
    DuckDuckGoSearcher = None  # type: ignore[assignment]

__all__ = [
    # Middleware-native (always available)
    "BochaSearchTool",
    # Extracted to isage-tools (available when installed)
    "ArxivPaperSearcher",
    "_Searcher_Tool",  # compat alias
    "ArxivSearcher",
    "DuckDuckGoSearcher",
    "NatureNewsFetcherTool",
    "Nature_News_Fetcher_Tool",  # compat alias
    "URLTextExtractorTool",
    "URL_Text_Extractor_Tool",  # compat alias
]
