#!/usr/bin/env python3
"""
#exonware/xwquery/tests/0.core/test_operations.py
Core tests for all 58+ operations - Verify operation coverage
Company: eXonware.com
Author: eXonware Backend Team
Email: connect@exonware.com
Version: 0.1.0
Generation Date: October 26, 2025
"""

import pytest
from exonware.xwquery import XWQuery
@pytest.mark.xwquery_core

class TestCoreOperations:
    """Test core CRUD operations (SELECT, INSERT, UPDATE, DELETE, CREATE, DROP)."""
    @pytest.mark.parametrize("operation,query", [
        pytest.param("SELECT", "SELECT * FROM users", id="select"),
        pytest.param("INSERT", "INSERT INTO users VALUES {name: 'Alice'}", id="insert"),
        pytest.param("UPDATE", "UPDATE users SET age = 30", id="update"),
        pytest.param("DELETE", "DELETE FROM users WHERE age < 18", id="delete"),
        pytest.param("CREATE", "CREATE TABLE users", id="create"),
        pytest.param("DROP", "DROP TABLE users", id="drop"),
    ])

    def test_core_operation_recognized(self, operation, query):
        """Test that core operations are recognized."""
        # Validate query is recognized
        is_valid = XWQuery.validate(query)
        print(f"[TEST] {operation}: valid={is_valid}, query='{query}'")
        # All core operations should validate
        assert is_valid, f"{operation} should be recognized as valid"
@pytest.mark.xwquery_core

class TestFilteringOperations:
    """Test filtering operations (WHERE, FILTER, LIKE, IN, HAS, etc.)."""
    @pytest.mark.parametrize("operation,query", [
        pytest.param("WHERE", "SELECT * FROM users WHERE age > 25", id="where"),
        pytest.param("FILTER", "SELECT * FROM users FILTER name = 'Alice'", id="filter"),
        pytest.param("LIKE", "SELECT * FROM users WHERE name LIKE 'Al%'", id="like"),
        pytest.param("IN", "SELECT * FROM users WHERE id IN [1,2,3]", id="in"),
        pytest.param("BETWEEN", "SELECT * FROM users WHERE age BETWEEN 20 AND 30", id="between"),
    ])

    def test_filtering_operation_recognized(self, operation, query):
        """Test that filtering operations are recognized."""
        is_valid = XWQuery.validate(query)
        print(f"[TEST] {operation}: valid={is_valid}")
        # Note: Some operations might not validate perfectly yet (v0.x)
        # But they should be recognized by the system
        supported_ops = XWQuery.get_supported_operations()
        assert operation in supported_ops, f"{operation} should be in supported operations"
@pytest.mark.xwquery_core

class TestAggregationOperations:
    """Test aggregation operations (COUNT, SUM, AVG, MIN, MAX, etc.)."""
    @pytest.mark.parametrize("operation", [
        "COUNT", "SUM", "AVG", "MIN", "MAX", 
        "DISTINCT", "GROUP", "HAVING"
    ])

    def test_aggregation_operation_supported(self, operation):
        """Test that aggregation operations are supported."""
        supported_ops = XWQuery.get_supported_operations()
        assert operation in supported_ops, f"{operation} should be supported"
        print(f"[OK] {operation} is supported")
@pytest.mark.xwquery_core

class TestGraphOperations:
    """Test graph operations (MATCH, PATH, OUT, IN, RETURN)."""
    @pytest.mark.parametrize("operation", [
        "MATCH", "PATH", "OUT", "IN", "RETURN"
    ])

    def test_graph_operation_supported(self, operation):
        """Test that graph operations are supported."""
        supported_ops = XWQuery.get_supported_operations()
        assert operation in supported_ops, f"{operation} should be supported"
        print(f"[OK] {operation} is supported")
@pytest.mark.xwquery_core

class TestAdvancedOperations:
    """Test advanced operations (JOIN, UNION, WINDOW, etc.)."""
    @pytest.mark.parametrize("operation", [
        "JOIN", "UNION", "WITH", "AGGREGATE",
        "FOREACH", "LET", "FOR", "WINDOW"
    ])

    def test_advanced_operation_supported(self, operation):
        """Test that advanced operations are supported."""
        supported_ops = XWQuery.get_supported_operations()
        assert operation in supported_ops, f"{operation} should be supported"
        print(f"[OK] {operation} is supported")
@pytest.mark.xwquery_core

class TestAllOperationsCovered:
    """Test that we have comprehensive operation coverage."""

    def test_minimum_operation_count(self):
        """Test that we support at least 50+ operations."""
        supported_ops = XWQuery.get_supported_operations()
        count = len(supported_ops)
        assert count >= 50, f"Should support at least 50 operations, found {count}"
        print(f"[OK] {count} operations supported (target: 50+)")

    def test_all_operation_categories_present(self):
        """Test that all operation categories are represented."""
        supported_ops = XWQuery.get_supported_operations()
        # Core operations
        core_ops = ["SELECT", "INSERT", "UPDATE", "DELETE", "CREATE", "DROP"]
        for op in core_ops:
            assert op in supported_ops, f"Core operation {op} missing"
        # Filtering operations
        filter_ops = ["WHERE", "FILTER", "IN"]
        for op in filter_ops:
            assert op in supported_ops, f"Filtering operation {op} missing"
        # Aggregation operations
        agg_ops = ["COUNT", "SUM", "AVG"]
        for op in agg_ops:
            assert op in supported_ops, f"Aggregation operation {op} missing"
        # Graph operations
        graph_ops = ["MATCH", "RETURN"]
        for op in graph_ops:
            assert op in supported_ops, f"Graph operation {op} missing"
        print("[OK] All operation categories present")
