#!/usr/bin/env python3
"""
Simple validation script to check if the test suite is set up correctly.
"""

import sys
import os

def check_files():
    """Check if all test files exist and are readable"""
    required_files = [
        'alloy_interpreter.py',
        'test_alloy_features.py',
        'test_parser_only.py',
        'test_error_cases.py', 
        'test_examples.py',
        'run_all_tests.py'
    ]
    
    print("🔍 Checking required files...")
    all_present = True
    
    for filename in required_files:
        if os.path.exists(filename):
            print(f"✅ {filename}")
        else:
            print(f"❌ {filename} - NOT FOUND")
            all_present = False
    
    return all_present

def check_imports():
    """Check if imports work correctly"""
    print("\n🔍 Checking imports...")
    
    try:
        import alloy_interpreter
        print("✅ alloy_interpreter imported successfully")
        
        # Check if parser exists
        if hasattr(alloy_interpreter, 'parser'):
            print("✅ Parser found in alloy_interpreter")
        else:
            print("❌ Parser not found in alloy_interpreter")
            return False
            
        # Check if Interpreter class exists
        if hasattr(alloy_interpreter, 'Interpreter'):
            print("✅ Interpreter class found")
        else:
            print("❌ Interpreter class not found")
            return False
            
        return True
        
    except ImportError as e:
        print(f"❌ Failed to import alloy_interpreter: {e}")
        return False

def test_basic_parsing():
    """Test basic parsing functionality"""
    print("\n🔍 Testing basic parsing...")
    
    try:
        import alloy_interpreter
        
        # Test simple parsing
        test_code = 'x = 42'
        ast = alloy_interpreter.parser.parse(test_code)
        
        if ast is not None:
            print("✅ Basic parsing works")
            return True
        else:
            print("❌ Basic parsing returned None")
            return False
            
    except Exception as e:
        print(f"❌ Basic parsing failed: {e}")
        return False

def test_basic_interpretation():
    """Test basic interpretation functionality"""
    print("\n🔍 Testing basic interpretation...")
    
    try:
        import alloy_interpreter
        
        # Test simple interpretation
        test_code = 'x = 42'
        ast = alloy_interpreter.parser.parse(test_code)
        interpreter = alloy_interpreter.Interpreter()
        interpreter.interpret(ast)
        
        result = interpreter.global_env.get('x')
        if result == 42:
            print("✅ Basic interpretation works")
            return True
        else:
            print(f"❌ Basic interpretation failed: expected 42, got {result}")
            return False
            
    except Exception as e:
        print(f"❌ Basic interpretation failed: {e}")
        return False

def main():
    """Main validation function"""
    print("🧪 ALLOY TEST SUITE VALIDATION")
    print("=" * 50)
    
    checks = [
        ("File Check", check_files),
        ("Import Check", check_imports),
        ("Parsing Check", test_basic_parsing),
        ("Interpretation Check", test_basic_interpretation),
    ]
    
    all_passed = True
    
    for check_name, check_func in checks:
        print(f"\n📋 {check_name}")
        print("-" * 30)
        
        if not check_func():
            all_passed = False
    
    print("\n" + "=" * 50)
    if all_passed:
        print("🎉 ALL VALIDATIONS PASSED!")
        print("The test suite should work correctly.")
        print("\nTo run tests:")
        print("  python run_all_tests.py           # All tests")
        print("  python run_all_tests.py parser    # Parser tests only")
        print("  python test_alloy_features.py     # Core feature tests")
    else:
        print("❌ SOME VALIDATIONS FAILED!")
        print("Please fix the issues above before running the full test suite.")
    
    return 0 if all_passed else 1

if __name__ == '__main__':
    sys.exit(main())