
import logging
from typing import List, Any

# ADK Imports (Polyfill if missing)
try:
    from google.adk.tools import FunctionTool
except ImportError:
    class FunctionTool:
        def __init__(self, func, require_confirmation=False):
            self.func = func

from core.action.auto_browse import browser

logger = logging.getLogger(__name__)

# --- Tool Wrappers ---

async def navigate_web(url: str) -> str:
    """Navigates the browser to the specified URL."""
    return await browser.navigate(url)

async def click_element(selector: str) -> str:
    """Clicks an element on the active page identified by the CSS selector."""
    return await browser.click(selector)

async def type_into_element(selector: str, text: str) -> str:
    """Types text into an element on the active page."""
    return await browser.type_text(selector, text)

async def scroll_page(direction: str = "down", amount: int = 500) -> str:
    """Scrolls the page up or down."""
    return await browser.scroll(direction, amount)

async def view_page_state() -> str:
    """Returns the current text content of the page."""
    return await browser.get_state()

# --- Registry ---

def get_native_tools() -> List[FunctionTool]:
    """
    Returns the list of Native Antigravity Tools.
    """
    return [
        FunctionTool(navigate_web),
        FunctionTool(click_element),
        FunctionTool(type_into_element),
        FunctionTool(scroll_page),
        FunctionTool(view_page_state)
    ]
