"""
Data processing and structured extraction tools
"""

from mcp.types import Tool


def get_data_tools():
    """Return tools for data processing and structured extraction."""
    return [
        Tool(
            name="parse_page",
            description="Complete page parsing: fetch HTML and extract structured data",
            inputSchema={
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL of the web page to parse"
                    },
                    "extract_title": {
                        "type": "boolean",
                        "description": "Extract page title (default: true)",
                        "default": True
                    },
                    "extract_meta": {
                        "type": "boolean",
                        "description": "Extract meta tags (default: true)",
                        "default": True
                    },
                    "extract_links": {
                        "type": "boolean",
                        "description": "Extract all links (default: false)",
                        "default": False
                    },
                    "extract_images": {
                        "type": "boolean",
                        "description": "Extract all images (default: false)",
                        "default": False
                    },
                    "custom_selectors": {
                        "type": "object",
                        "description": "Custom CSS selectors to extract specific content",
                        "default": {}
                    },
                    "verbose": {
                        "type": "boolean",
                        "description": "Enable detailed extraction analysis",
                        "default": True
                    },
                    "smart_extraction": {
                        "type": "boolean",
                        "description": "Enable smart fallback selectors",
                        "default": True
                    }
                },
                "required": ["url"]
            }
        ),

        Tool(
            name="extract_structured_data",
            description="Extract structured data using predefined schemas",
            inputSchema={
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL to extract data from (alternative to html)"
                    },
                    "html": {
                        "type": "string",
                        "description": "HTML content to extract data from (alternative to url)"
                    },
                    "schema": {
                        "type": "string",
                        "description": "Predefined schema: 'product', 'article', 'person', 'event', 'course', 'job', 'review', 'custom'",
                        "default": "custom"
                    },
                    "custom_schema": {
                        "type": "object",
                        "description": "Custom extraction schema with field mappings",
                        "default": {}
                    },
                    "output_format": {
                        "type": "string",
                        "description": "Output format: 'json', 'csv', 'table'",
                        "default": "json"
                    }
                }
            }
        ),

        Tool(
            name="cache_results",
            description="Cache fetch results for improved performance",
            inputSchema={
                "type": "object",
                "properties": {
                    "action": {
                        "type": "string",
                        "description": "Cache action: 'get', 'set', 'clear', 'stats'",
                        "enum": ["get", "set", "clear", "stats"]
                    },
                    "key": {
                        "type": "string",
                        "description": "Cache key (URL or custom key)"
                    },
                    "value": {
                        "type": "string",
                        "description": "Value to cache (for 'set' action)"
                    },
                    "duration": {
                        "type": "string",
                        "description": "Cache duration: '1h', '1d', '1w' (default: '1h')",
                        "default": "1h"
                    },
                    "storage": {
                        "type": "string",
                        "description": "Storage type: 'memory', 'file' (default: 'memory')",
                        "default": "memory"
                    }
                },
                "required": ["action"]
            }
        )
    ]
