"""
Storm Logger test patterns and filtering strategies
"""

import json
from typing import Dict, Any, List


def get_test_patterns() -> str:
    """
    Database of test patterns and filtering strategies for Storm Logger
    
    Returns:
        JSON string with test patterns, naming conventions, and filter examples
    """
    patterns_data = {
        "title": "Storm Logger Test Patterns & -k Filtering Guide",
        "storm_script_magic": {
            "new_feature": "The Storm test script now supports -k filtering!",
            "syntax": "./test.sh -k PATTERN [other options]",
            "examples": [
                "./test.sh -k test_table_printing",
                "./test.sh -k TestStormConsole", 
                "./test.sh -k 'console and print'",
                "./test.sh -k logger --quick"
            ]
        },
        
        "naming_conventions": {
            "test_files": {
                "pattern": "test_*.py",
                "examples": ["test_console.py", "test_logger.py", "test_config.py"],
                "location": "tests/unit/, tests/integration/, etc."
            },
            "test_classes": {
                "pattern": "Test*",
                "examples": ["TestStormConsole", "TestStormLogger", "TestConfiguration"],
                "purpose": "Group related test methods"
            },
            "test_methods": {
                "pattern": "test_*",
                "examples": ["test_table_printing", "test_error_handling", "test_business_metrics"],
                "naming": "Descriptive of what is being tested"
            }
        },
        
        "effective_k_patterns": {
            "by_component": {
                "console": ["console", "StormConsole", "print", "table", "format"],
                "logger": ["logger", "StormLogger", "ProfessionalLogger", "business"],
                "config": ["config", "Configuration", "django", "validation"],
                "integration": ["django", "standalone", "integration"]
            },
            "by_functionality": {
                "formatting": ["format", "message", "color", "theme"],
                "metrics": ["metric", "business", "performance", "track"],
                "error_handling": ["error", "exception", "failure", "recovery"],
                "sanitization": ["sanitize", "pii", "security", "clean"]
            },
            "by_test_type": {
                "unit": ["unit", "isolated", "mock"],
                "integration": ["integration", "django", "database"],
                "functional": ["functional", "workflow", "scenario"],
                "performance": ["performance", "benchmark", "speed"]
            }
        },
        
        "boolean_combinations": {
            "examples": [
                "./test.sh -k 'console and table'",
                "./test.sh -k 'logger and not django'",
                "./test.sh -k 'format or print'",
                "./test.sh -k 'test_business and metrics'"
            ],
            "operators": {
                "and": "Both conditions must be true",
                "or": "Either condition can be true",
                "not": "Exclude matching patterns"
            }
        },
        
        "common_workflows": {
            "debugging_single_test": {
                "purpose": "Debug a specific failing test",
                "command": "./test.sh -k test_name -v",
                "next_steps": ["Fix the issue", "Re-run with same command", "Expand to related tests"]
            },
            "component_testing": {
                "purpose": "Test all aspects of a component",
                "command": "./test.sh -k component_name --quick",
                "examples": ["./test.sh -k console --quick", "./test.sh -k logger --quick"]
            },
            "feature_development": {
                "purpose": "Test new feature during development",
                "command": "./test.sh -k feature_keyword --progress",
                "workflow": ["Write test", "Run with -k", "Implement feature", "Re-run", "Expand tests"]
            }
        },
        
        "expert_tips": [
            "Use quotes for complex patterns: -k 'console and table'",
            "Test class filtering is powerful: -k TestStormConsole",
            "Combine with --quick for faster feedback",
            "Use -v for detailed debugging output",
            "The Storm script suggests -k usage in error messages!"
        ]
    }
    
    return json.dumps(patterns_data, indent=2)


def get_test_filtering_strategies() -> Dict[str, Any]:
    """
    Get advanced test filtering strategies
    
    Returns:
        Dictionary with filtering strategies and examples
    """
    return {
        "development_phases": {
            "initial_development": {
                "focus": "Single test or small group",
                "commands": [
                    "./test.sh -k test_name -v",
                    "./test.sh -k TestClass --quick"
                ]
            },
            "feature_completion": {
                "focus": "All related tests",
                "commands": [
                    "./test.sh -k feature_name --quick",
                    "./test.sh -k 'feature or related' --progress"
                ]
            },
            "regression_testing": {
                "focus": "Broader scope validation",
                "commands": [
                    "./test.sh --quick",
                    "./test.sh -k 'not performance'"
                ]
            }
        },
        "error_patterns": {
            "import_errors": {
                "filters": ["-k test_file", "-k module_name"],
                "purpose": "Test specific imports and dependencies"
            },
            "assertion_failures": {
                "filters": ["-k test_method", "-k functionality"],
                "purpose": "Focus on specific business logic"
            },
            "parameter_issues": {
                "filters": ["-k method_name", "-k TestClass"],
                "purpose": "Test method signatures and calls"
            }
        },
        "component_mapping": {
            "console": {
                "keywords": ["console", "print", "table", "format", "theme"],
                "classes": ["TestStormConsole", "TestConsoleFormatter"],
                "files": ["test_console.py", "test_storm_console.py"]
            },
            "logger": {
                "keywords": ["logger", "business", "professional", "track"],
                "classes": ["TestStormLogger", "TestProfessionalLogger"],
                "files": ["test_logger.py", "test_professional_logger.py"]
            },
            "config": {
                "keywords": ["config", "django", "validation", "setup"],
                "classes": ["TestConfiguration", "TestDjangoConfig"],
                "files": ["test_config.py", "test_django_config.py"]
            }
        }
    }


def get_test_naming_patterns() -> Dict[str, Any]:
    """
    Get test naming patterns and conventions
    
    Returns:
        Dictionary with naming patterns and examples
    """
    return {
        "file_naming": {
            "unit_tests": {
                "pattern": "test_<module>.py",
                "examples": [
                    "test_console.py",
                    "test_logger.py",
                    "test_formatters.py",
                    "test_business_metrics.py"
                ]
            },
            "integration_tests": {
                "pattern": "test_<component>_integration.py",
                "examples": [
                    "test_django_integration.py",
                    "test_flask_integration.py",
                    "test_standalone_integration.py"
                ]
            },
            "functional_tests": {
                "pattern": "test_<workflow>_functional.py",
                "examples": [
                    "test_business_workflow_functional.py",
                    "test_logging_pipeline_functional.py"
                ]
            }
        },
        "class_naming": {
            "unit_test_classes": {
                "pattern": "Test<ModuleName>",
                "examples": [
                    "TestStormConsole",
                    "TestStormLogger",
                    "TestBusinessMetrics",
                    "TestMessageFormatter"
                ]
            },
            "integration_test_classes": {
                "pattern": "Test<Component>Integration",
                "examples": [
                    "TestDjangoIntegration",
                    "TestFlaskIntegration",
                    "TestStandaloneIntegration"
                ]
            }
        },
        "method_naming": {
            "positive_tests": {
                "pattern": "test_<functionality>",
                "examples": [
                    "test_table_printing",
                    "test_business_event_tracking",
                    "test_error_formatting"
                ]
            },
            "negative_tests": {
                "pattern": "test_<functionality>_error",
                "examples": [
                    "test_invalid_input_error",
                    "test_missing_config_error",
                    "test_connection_timeout_error"
                ]
            },
            "edge_cases": {
                "pattern": "test_<functionality>_edge_case",
                "examples": [
                    "test_empty_input_edge_case",
                    "test_max_length_edge_case",
                    "test_unicode_edge_case"
                ]
            }
        }
    }


def get_filter_examples_by_scenario() -> Dict[str, Any]:
    """
    Get filter examples organized by common scenarios
    
    Returns:
        Dictionary with scenario-based filter examples
    """
    return {
        "debugging_scenarios": {
            "single_failing_test": {
                "description": "Debug one specific failing test",
                "command": "./test.sh -k test_specific_name -v",
                "tips": ["Use exact test name", "Add -v for verbose output"]
            },
            "class_of_failures": {
                "description": "Debug all tests in a test class",
                "command": "./test.sh -k TestClassName -v",
                "tips": ["Use class name without quotes", "Combine with --quick if needed"]
            },
            "feature_area_issues": {
                "description": "Debug all tests related to a feature",
                "command": "./test.sh -k feature_name --quick",
                "tips": ["Use feature keywords", "Start with --quick for faster feedback"]
            }
        },
        "development_scenarios": {
            "new_feature_development": {
                "description": "Test new feature during development",
                "command": "./test.sh -k new_feature --progress",
                "workflow": [
                    "Write failing test",
                    "Run with -k to see failure",
                    "Implement feature",
                    "Re-run until passing",
                    "Expand test coverage"
                ]
            },
            "refactoring_validation": {
                "description": "Validate refactoring doesn't break functionality",
                "command": "./test.sh -k affected_component --quick",
                "tips": ["Test all affected components", "Use --quick for faster feedback"]
            }
        },
        "maintenance_scenarios": {
            "regression_testing": {
                "description": "Test for regressions after changes",
                "command": "./test.sh -k 'not performance' --quick",
                "tips": ["Exclude slow tests initially", "Run full suite if needed"]
            },
            "performance_validation": {
                "description": "Validate performance-sensitive code",
                "command": "./test.sh -k performance --benchmark",
                "tips": ["Use benchmark flag", "Focus on performance tests"]
            }
        }
    }