{
  "type": "object",
  "additionalProperties": false,
  "required": ["patches"],
  "properties": {
    "patches": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["operation", "source_line_id", "line_total", "quantity", "unit_price", "selected_candidate", "confidence", "evidence_text"],
        "properties": {
          "operation": {"enum": ["fill_missing_line_total", "replace_conflicting_line_total", "select_candidate", "confirm_weighted_values"]},
          "source_line_id": {"type": "string", "pattern": "^ocr-line-[0-9]+$"},
          "line_total": {"type": ["number", "null"]},
          "quantity": {"type": ["number", "null"]},
          "unit_price": {"type": ["number", "null"]},
          "selected_candidate": {"type": ["number", "null"]},
          "confidence": {"type": "number", "minimum": 0, "maximum": 1},
          "evidence_text": {"type": "string", "maxLength": 500}
        }
      }
    }
  }
}
