import asyncio
import sys
from pathlib import Path
import httpx

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))


async def check_api_health(base_url: str = "http://127.0.0.1:8000"):
    print(f"🔍 Checking health at {base_url}...")
    try:
        async with httpx.AsyncClient() as client:
            resp = await client.get(f"{base_url}/api/v1/health/detailed", timeout=5.0)
            print(f"Status Code: {resp.status_code}")
            print(f"Response: {resp.json()}")
            if resp.status_code == 200:
                print("✅ System is healthy!")
            else:
                print("⚠️ System returned non-200 status.")
    except Exception as exc:
        print(f"❌ Failed to connect: {exc}")


if __name__ == "__main__":
    url = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:8000"
    asyncio.run(check_api_health(url))
