/**
 * createRuntime - Bootstrap the full AirCoding runtime
 * DD §22.2. Wires all subsystems via ServiceRegistry.
 *
 * @module packages/cli/src/bootstrap/createRuntime
 */

import { RuntimeApp } from '@aircoding/runtime'
import type { AirConfig } from './loadConfig.js'

export interface BootResult {
  app: RuntimeApp
  start: () => Promise<void>
  shutdown: () => Promise<void>
}

/**
 * Create and start the AirCoding runtime.
 */
export async function createRuntime(config: AirConfig): Promise<BootResult> {
  const project_root = config.project_root || process.cwd()

  // Generate session and project IDs
  const session_id = `session_${Date.now()}`
  const project_id = `project_${Date.now()}` // Would be loaded from .air/shared/project.json

  const app = new RuntimeApp({
    project_root,
    session_id,
    project_id,
    log_dir: `${project_root}/.air/logs`
  })

  return {
    app,
    start: () => app.start(),
    shutdown: () => app.shutdown()
  }
}
