"""
Fetch and basic data extraction tools
"""

from mcp.types import Tool


def get_fetch_tools():
    """Return tools for fetching and basic data extraction."""
    return [
        Tool(
            name="fetch_html",
            description="🚶 Fetch HTML content using realistic human-like browser navigation with keyboard input, mouse movements, and scrolling",
            inputSchema={
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL of the web page to fetch"
                    },
                    "timeout": {
                        "type": "number",
                        "description": "Request timeout in seconds (default: 10)",
                        "default": 10
                    },
                    "headers": {
                        "type": "object",
                        "description": "Custom headers to send with the request",
                        "default": {}
                    },
                    "use_browser": {
                        "type": "boolean",
                        "description": "Force use Playwright browser for JS-heavy sites (default: false)",
                        "default": False
                    },
                    "wait_for": {
                        "type": "string",
                        "description": "CSS selector to wait for before getting content (requires use_browser=true)"
                    },
                    "import_cookies_from": {
                        "type": "string",
                        "description": "Import cookies from browser: 'chrome', 'firefox', 'edge', 'safari'"
                    },
                    "anti_detection": {
                        "type": "boolean",
                        "description": "Enable anti-detection measures (random headers, etc.)",
                        "default": False
                    },
                    "debug": {
                        "type": "boolean",
                        "description": "Enable detailed logging and debugging",
                        "default": False
                    },
                    "stealth": {
                        "type": "boolean",
                        "description": "Enable stealth mode to avoid detection (requires use_browser=true)",
                        "default": False
                    }
                },
                "required": ["url"]
            }
        ),
        
        Tool(
            name="extract_text",
            description="Extract clean text content from HTML",
            inputSchema={
                "type": "object",
                "properties": {
                    "html": {
                        "type": "string",
                        "description": "HTML content to extract text from"
                    },
                    "preserve_formatting": {
                        "type": "boolean",
                        "description": "Whether to preserve line breaks and spacing (default: false)",
                        "default": False
                    }
                },
                "required": ["html"]
            }
        ),

        Tool(
            name="find_elements",
            description="Find HTML elements using CSS selectors or tag names",
            inputSchema={
                "type": "object",
                "properties": {
                    "html": {
                        "type": "string",
                        "description": "HTML content to search in"
                    },
                    "selector": {
                        "type": "string",
                        "description": "CSS selector to find elements (e.g., 'div.class', '#id', 'a[href]')"
                    },
                    "attribute": {
                        "type": "string",
                        "description": "Specific attribute to extract from found elements",
                        "default": None
                    },
                    "limit": {
                        "type": "number",
                        "description": "Maximum number of elements to return (default: 10)",
                        "default": 10
                    }
                },
                "required": ["html", "selector"]
            }
        ),

        Tool(
            name="extract_links",
            description="Extract and filter links from HTML or URL with advanced options",
            inputSchema={
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL of the web page to extract links from (alternative to html)"
                    },
                    "html": {
                        "type": "string",
                        "description": "HTML content to extract links from (alternative to url)"
                    },
                    "base_url": {
                        "type": "string",
                        "description": "Base URL for resolving relative links"
                    },
                    "internal_only": {
                        "type": "boolean",
                        "description": "Only return internal links (same domain)",
                        "default": False
                    },
                    "external_only": {
                        "type": "boolean",
                        "description": "Only return external links (different domain)",
                        "default": False
                    },
                    "url_pattern": {
                        "type": "string",
                        "description": "Regex pattern to filter URLs"
                    },
                    "text_pattern": {
                        "type": "string",
                        "description": "Regex pattern to filter link text"
                    },
                    "exclude_fragments": {
                        "type": "boolean",
                        "description": "Exclude fragment links (#section)",
                        "default": True
                    },
                    "unique_only": {
                        "type": "boolean",
                        "description": "Return only unique URLs",
                        "default": True
                    },
                    "limit": {
                        "type": "number",
                        "description": "Maximum number of links to return",
                        "default": 100
                    }
                }
            }
        )
    ]
