"""ClawPrintToolkit — convenience wrapper that bundles all six tools.

Usage::

    from clawprint_langchain import ClawPrintToolkit

    toolkit = ClawPrintToolkit(api_key="cp_live_...")
    tools = toolkit.get_tools()
"""

from __future__ import annotations

import os
from typing import List, Optional

from langchain_core.tools import BaseTool

from clawprint_langchain.client import ClawPrintClient, CLAWPRINT_DEFAULT_BASE_URL
from clawprint_langchain.tools import (
    ClawPrintCheckExchangeTool,
    ClawPrintDomainsTool,
    ClawPrintGetAgentTool,
    ClawPrintHireAgentTool,
    ClawPrintSearchTool,
    ClawPrintTrustTool,
)


class ClawPrintToolkit:
    """Bundle every ClawPrint tool behind a single entry point.

    Parameters
    ----------
    api_key:
        ClawPrint API key.  Falls back to the ``CLAWPRINT_API_KEY``
        environment variable.  Required only for exchange/hire endpoints.
    base_url:
        Override the default API base URL.
    timeout:
        HTTP request timeout in seconds.

    Example
    -------
    >>> from clawprint_langchain import ClawPrintToolkit
    >>> toolkit = ClawPrintToolkit(api_key="cp_live_...")
    >>> tools = toolkit.get_tools()
    """

    def __init__(
        self,
        api_key: Optional[str] = None,
        base_url: str = CLAWPRINT_DEFAULT_BASE_URL,
        timeout: int = 30,
    ) -> None:
        resolved_key = api_key or os.environ.get("CLAWPRINT_API_KEY")
        self._client = ClawPrintClient(
            api_key=resolved_key,
            base_url=base_url,
            timeout=timeout,
        )

    def get_tools(self) -> List[BaseTool]:
        """Return all six ClawPrint tools wired to a shared HTTP client.

        Tools that require authentication (hire, check exchange) will
        raise at call time if no API key was provided.
        """
        c = self._client
        return [
            ClawPrintSearchTool(client=c),
            ClawPrintGetAgentTool(client=c),
            ClawPrintTrustTool(client=c),
            ClawPrintDomainsTool(client=c),
            ClawPrintHireAgentTool(client=c),
            ClawPrintCheckExchangeTool(client=c),
        ]