// INVYONE Stage-2 — Bootstrap
// 1) 토폴로지에서 SVG 씬 생성  2) 엔진 초기화  3) UI 와이어업  4) tick 시작

(function () {
  function boot() {
    const sceneEl = document.getElementById('scene-content');
    if (!sceneEl) {
      console.error('#scene-content 노드를 찾을 수 없음');
      return;
    }
    sceneEl.innerHTML = window.INVYONE_TOPO.buildScene();

    window.INVYONE_ENGINE.init();
    window.INVYONE_UI.init();
    window.INVYONE_ENGINE.start();

    // expose for browser console
    window.INVYONE = {
      engine:   window.INVYONE_ENGINE,
      topo:     window.INVYONE_TOPO,
      ui:       window.INVYONE_UI,
      scenario: window.INVYONE_SCENARIO,
      // 빠른 콘솔 데모 헬퍼
      help() {
        console.log('%cINVYONE Stage-2 Demo', 'color:#5af9ff;font-size:14px');
        console.log('console 사용법:');
        console.log('  INVYONE.engine.applyMode("NORMAL"|"BACKWASH"|"CIP"|"STOP"|"CHEM-DOSE")');
        console.log('  INVYONE.engine.togglePump("uf-pump-a")');
        console.log('  INVYONE.engine.toggleValve("v-uf-in")');
        console.log('  INVYONE.engine.setTankLevel("raw", 90)');
        console.log('  INVYONE.engine.setSensor("ph", 9.5)');
        console.log('  INVYONE.engine.triggerDemoAlarm()');
        console.log('  INVYONE.engine.reset()');
        console.log('  INVYONE.scenario.play("bw-a1-overpressure")  — 경고시스템 시연');
        console.log('  INVYONE.scenario.stop()');
        console.log('  INVYONE.engine.state — 전체 상태 객체');
      }
    };
    console.log('%cINVYONE Stage-2 Ready — INVYONE.help() 입력', 'color:#7cff3a');
  }

  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);
  else boot();
})();
