#!/usr/bin/env python3
"""
AI Browser Extension Server Management
Linux/WSL wrapper for unified Python server manager
"""

import sys
import os
from pathlib import Path

def main():
    # Get script directory
    script_dir = Path(__file__).parent
    
    # Activate virtual environment if it exists
    venv_paths = [
        script_dir / ".venv" / "bin" / "activate",
        script_dir / "venv" / "bin" / "activate"
    ]
    
    for venv_path in venv_paths:
        if venv_path.exists():
            # Set environment variables as if we activated
            venv_dir = venv_path.parent.parent
            os.environ["VIRTUAL_ENV"] = str(venv_dir)
            os.environ["PATH"] = f"{venv_dir}/bin:{os.environ.get('PATH', '')}"
            break
    else:
        print("Warning: No virtual environment found")
    
    # Import and call the unified manager
    sys.path.insert(0, str(script_dir))
    from server_manager import main as manager_main
    
    # Check arguments and provide correct usage
    if len(sys.argv) < 2:
        print("Usage: ./server {start|stop|restart|status}")
        sys.exit(1)
    
    # Call with same arguments
    manager_main()

if __name__ == "__main__":
    main()