"""Quick test for P2-M2 generation endpoints."""
from fastapi.testclient import TestClient
from app.main import app

client = TestClient(app)

# 1. Scan parameters
r = client.get("/api/scan-parameters")
data = r.json()
print(f"[1] scan-parameters: {r.status_code}, total={data['total']}")
for p in data["parameters"]:
    print(f"    {p['name']} ({p['category']}): {p['default_start']}-{p['default_stop']} {p['unit']}")

# 2. Recommend range for Airgap with BC
r2 = client.post("/api/recommend-range", json={
    "parameter_name": "Airgap",
    "boundary_conditions": {"outer_diameter_mm": 76, "target_torque_nm": 2.0},
})
print(f"\n[2] recommend-range Airgap: {r2.status_code}")
print(f"    {r2.json()}")

# 3. Generate plan from BC
r3 = client.post("/api/generate-plan", json={
    "boundary_conditions": {
        "topology": "SSSR",
        "outer_diameter_mm": 76,
        "inner_diameter_mm": 40,
        "speed_rpm": 5000,
        "current_a": 21,
        "magnet_temp_c": 100,
    },
    "model_path": "models/MARS-12S10P_SSSR_D76-C150_V5.0-0819.mot",
})
print(f"\n[3] generate-plan: {r3.status_code}")
plan = r3.json()
print(f"    name: {plan['name']}")
print(f"    topology: {plan['topology']}")
print(f"    estimated_points: {plan['estimated_points']}")
print(f"    estimated_time_min: {plan['estimated_time_min']}")
for v in plan["variables"]:
    print(f"    {v['name']}: start={v['start']}, stop={v['stop']}, step={v['step']}, values={v['values']}")
    print(f"      notes: {v['recommendation_notes']}")

# 4. Generate plan with specific parameters
r4 = client.post("/api/generate-plan", json={
    "boundary_conditions": {"outer_diameter_mm": 76, "current_a": 21},
    "parameter_names": ["Airgap", "RMSCurrent"],
})
print(f"\n[4] generate-plan (custom params): {r4.status_code}")
plan4 = r4.json()
print(f"    variables: {[v['name'] for v in plan4['variables']]}")
print(f"    points: {plan4['estimated_points']}")

print("\n=== ALL GENERATION TESTS PASSED ===")
