/**
 * Data provenance and truth labels (§81, §82).
 *
 * This platform shows measured readings, model outputs and simulation results on the
 * same screen, often in the same table. Anywhere those three are indistinguishable, the
 * interface is lying by omission — an operator reading a simulated temperature as an
 * instrument reading is the specific failure mode a tool like this must not have.
 *
 * So every figure carries a source, and the source is a first-class value rather than a
 * styling choice. The vocabulary is deliberately small: six kinds, no overlap, each with
 * one visual treatment used everywhere.
 */

export const DATA_SOURCES = [
  'live',
  'simulated',
  'predicted',
  'estimated',
  'synthetic',
  'manual',
] as const
export type DataSource = (typeof DATA_SOURCES)[number]

export interface Provenance {
  source: DataSource
  /** When the underlying value was produced. */
  ts: number
  /** Confidence in the value, 0–100, where the source admits one. */
  confidence?: number
  /** What produced it: a sensor code, an engine name, a model version. */
  producer?: string
}

/** The token family each source is drawn in. Colour never carries it alone. */
export const SOURCE_TONE: Record<DataSource, 'normal' | 'simulation' | 'ai' | 'accent' | 'muted'> = {
  live: 'normal',
  simulated: 'simulation',
  predicted: 'ai',
  estimated: 'accent',
  synthetic: 'muted',
  manual: 'muted',
}

/**
 * Operating modes (§6).
 *
 * The separation between these is a safety boundary, not a preference. A simulation and
 * a live view must never be mistakable for one another, which is why the mode is part of
 * the app shell rather than a setting buried in a page.
 */
export const APP_MODES = ['live', 'simulation', 'demo', 'sandbox'] as const
export type AppMode = (typeof APP_MODES)[number]

export const MODE_SOURCE: Record<AppMode, DataSource> = {
  live: 'live',
  simulation: 'simulated',
  demo: 'synthetic',
  sandbox: 'simulated',
}

/** True when nothing on screen should be read as an operational reading. */
export function isSimulatedMode(mode: AppMode): boolean {
  return mode !== 'live'
}

/**
 * Autonomy level (§92).
 *
 * Declared in code because it is a claim about what the software is permitted to do, and
 * a claim like that should be visible in the repository rather than only on a slide.
 */
export const AUTONOMY_LEVELS = [
  { level: 0, key: 'monitor' },
  { level: 1, key: 'predict' },
  { level: 2, key: 'recommend' },
  { level: 3, key: 'simulate' },
  { level: 4, key: 'approved_automation' },
] as const

/** The ceiling this build enforces. Nothing here can issue a control action. */
export const MAX_AUTONOMY_LEVEL = 3
