from typing import Optional

import logging

from uuid import UUID

from .frisk_callback_handler import FriskCallbackHandler
from .frisk_tool_middleware import FriskToolMiddleware
from .langchain_framework_adapter import LangchainFrameworkAdapter
from ...core import Frisk as FriskCore
from ...core.frisk_options import FriskOptionsInput


class FriskLangchain(FriskCore):
    """Frisk client preconfigured with the LangChain framework adapter."""

    def __init__(
        self,
        api_key: str,
        *,
        base_url: Optional[str] = None,
        logger: Optional[logging.Logger] = None,
        logger_name: Optional[str] = None,
        options: Optional[FriskOptionsInput] = None,
    ):
        super().__init__(
            api_key,
            base_url=base_url,
            framework_adapter=LangchainFrameworkAdapter(),
            logger=logger,
            logger_name=logger_name,
            options=options,
        )

    def callback_handler(self, session_id: UUID):
        """Create a LangChain callback handler bound to an existing Frisk session."""
        return FriskCallbackHandler(self, session_id)

    def tool_middleware(self):
        """Create LangChain tool middleware that enforces Frisk policy decisions."""
        return FriskToolMiddleware(self)
