#!/usr/bin/env python3
"""
MOXIE Startup Script
Quick launcher with environment checks.
"""
import sys
import subprocess
from pathlib import Path


def check_dependencies():
    """Check if required dependencies are installed."""
    required = [
        "fastapi",
        "uvicorn",
        "pydantic",
        "pydantic_settings",
        "ollama",
        "httpx",
        "duckduckgo_search",
        "jinja2",
        "loguru",
    ]
    
    missing = []
    for pkg in required:
        try:
            __import__(pkg.replace("-", "_"))
        except ImportError:
            missing.append(pkg)
    
    if missing:
        print(f"Missing dependencies: {', '.join(missing)}")
        print("\nInstall with: pip install -r requirements.txt")
        return False
    
    return True


def main():
    """Main entry point."""
    print("=" * 50)
    print("MOXIE - Fake Local LLM Orchestrator")
    print("=" * 50)
    print()
    
    # Check dependencies
    if not check_dependencies():
        sys.exit(1)
    
    # Import and run
    from main import app
    import uvicorn
    from config import settings
    
    print(f"Starting server on http://{settings.host}:{settings.port}")
    print(f"Admin UI: http://{settings.host}:{settings.port}/{settings.admin_path}")
    print()
    print("Press Ctrl+C to stop")
    print()
    
    uvicorn.run(
        "main:app",
        host=settings.host,
        port=settings.port,
        reload=settings.debug,
    )


if __name__ == "__main__":
    main()
