//! Z-factors must use embeddings[], not controls[]/SaturatedController.

use entropyk_cli::run::{run_simulation, SimulationStatus};
use tempfile::tempdir;

#[test]
fn controls_with_z_ua_are_rejected() {
    // Minimal config — reject happens before component graph build.
    let json = r#"
{
  "fluid": "R134a",
  "fluid_backend": "Test",
  "circuits": [],
  "controls": [
    {
      "type": "SaturatedController",
      "id": "bad_calib",
      "measure": { "component": "sst", "output": "saturationTemperature" },
      "actuator": { "component": "evap", "factor": "z_ua", "initial": 1, "min": 0.05, "max": 3 },
      "target": 278.15
    }
  ],
  "solver": { "strategy": "newton", "max_iterations": 10, "tolerance": 1e-6 }
}
"#;
    let dir = tempdir().unwrap();
    let path = dir.path().join("bad.json");
    std::fs::write(&path, json).unwrap();
    let result = run_simulation(&path, None, false).unwrap();
    assert!(
        matches!(result.status, SimulationStatus::Error),
        "expected Error, got {:?}",
        result.status
    );
    let err = result.error.unwrap_or_default();
    assert!(
        err.contains("embeddings") && err.contains("z_ua"),
        "error should point to embeddings[], got: {err}"
    );
}
