"""Quick test for API client."""
import sys
sys.path.insert(0, ".")
from src.api_client import WebAPIClient

client = WebAPIClient("http://127.0.0.1:8000")

print("Health:", client.health_check())

projects = client.list_projects()
print(f"Projects: {len(projects)}")
for p in projects:
    print(f"  #{p['id']}: {p['name']} ({p['topology']})")

plans = client.list_plans(project_id=1)
print(f"Plans for project 1: {len(plans)}")
for pl in plans:
    print(f"  #{pl['id']}: {pl['name']} ({pl['plan_id']}) status={pl['status']}")

if plans:
    plan = client.download_plan(plans[0]["id"])
    print(f"Downloaded plan: {plan['plan_id']}")
    vars_list = [v["name"] for v in plan["plan_data"].get("variables", [])]
    print(f"  Variables: {vars_list}")

    results = client.get_plan_results(plans[0]["id"])
    print(f"Results: {len(results)}")
    for r in results[:2]:
        tavg = r["metrics"].get("tavg_nm")
        eff = r["metrics"].get("efficiency_pct")
        print(f"  #{r['run_index']}: params={r['params']}, tavg={tavg}, eff={eff}")

print("API client test PASSED")
