{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "kadi-v2/schemas/value-stream-process-source.schema.json",
  "title": "VsmNodeQafSource",
  "description": "Quell-Herkunft eines importierten VSM-Prozess-Nodes — eingebettet als optionales Feld `qafSource` im Node-JSONB (value_stream_maps.nodes[]). Trägt je Feld Zelle, Original-Wert, Einheit und Confidence; Original-Werte bleiben bei manueller Änderung unangetastet (Spec 18).",
  "type": "object",
  "required": ["importId", "rowIndex"],
  "properties": {
    "importId": {
      "type": "string",
      "format": "uuid",
      "description": "FK auf value_stream_imports.id — dort liegen Datei, Hash, Parser-/Mapping-Version, Engine-Kontext (nicht je Node dupliziert)"
    },
    "sheet": { "type": ["string", "null"], "description": "Quell-Worksheet-Name" },
    "rowIndex": { "type": "integer", "minimum": 0, "description": "row_index aus qaf_manufacturing_step (Quell-Reihenfolge)" },
    "positionNumber": { "type": ["string", "null"] },
    "manufacturingStepId": {
      "type": ["string", "null"],
      "format": "uuid",
      "description": "FK auf qaf_manufacturing_step.id, falls beim Import verfügbar"
    },
    "fields": {
      "type": "object",
      "description": "Je QAF-Feld-Key (QAFFieldKey, z. B. zykluszeit, mss, ausschuss): Herkunft + Original. Enthält ALLE 22 extrahierten Quellfelder — auch die nur als Metadata gemappten (Detail-Panel).",
      "additionalProperties": {
        "type": "object",
        "required": ["original"],
        "properties": {
          "cell": { "type": ["string", "null"], "description": "Zell-Referenz \"Sheet!A1\" (aus sourceCells; null wenn nicht erfasst)" },
          "original": {
            "description": "Original-Wert zum Import-Zeitpunkt (Zahl, Text oder null bei explizitem n.a.-Marker)"
          },
          "rawText": { "type": ["string", "null"], "description": "Original-Zelltext bei nicht-numerischem Inhalt (n.a., entfällt) — Unterscheidung von leer" },
          "unit": { "type": ["string", "null"], "description": "Einheit lt. Canonical-Registry (s, %, BW/h, …)" },
          "confidence": { "type": ["number", "null"], "minimum": 0, "maximum": 1 },
          "mappedTo": { "type": ["string", "null"], "description": "VSM-Zielfeld (null = metadata-only)" }
        }
      }
    },
    "sequenceConfidence": {
      "enum": ["explicit", "row_order", "ambiguous", null],
      "description": "Wie sicher die Einordnung in die Prozess-Reihenfolge ist (Spec 7)"
    },
    "variantContext": {
      "type": ["object", "null"],
      "description": "Bei Multi-QAF-Quelle: geteilter Fluss + zugeordnete Varianten-Keys",
      "properties": {
        "shared": { "type": "boolean" },
        "variantKeys": { "type": "array", "items": { "type": "string" } }
      }
    }
  }
}
