/**
 * Types shared between the main thread and the WASM engine worker.
 * These mirror the JsResult struct from calcpad-wasm/src/types.rs.
 */

/** Result from evaluating a single line via the WASM engine. */
export interface EngineLineResult {
  /** Result type: number, unitValue, currencyValue, dateTime, timeDelta, boolean, error, text, comment, empty */
  type: string
  /** Display-formatted string of the result */
  display: string
  /** Raw numeric value, if applicable */
  rawValue: number | null
  /** Error message, if this is an error result */
  error: string | null
}

/** Messages sent from the main thread to the worker. */
export type WorkerRequest =
  | { kind: 'init' }
  | { kind: 'evalSheet'; id: number; lines: string[] }

/** Messages sent from the worker back to the main thread. */
export type WorkerResponse =
  | { kind: 'ready' }
  | { kind: 'initError'; error: string }
  | { kind: 'evalResult'; id: number; results: EngineLineResult[] }
  | { kind: 'evalError'; id: number; error: string }
