{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.horusbi.com.br/schemas/v2/flow.schema.json",
  "title": "Lumo v2 flow YAML",
  "type": "object",
  "required": [
    "header",
    "body"
  ],
  "properties": {
    "fileName": {
      "$ref": "shared.schema.json#/$defs/resourceFileName"
    },
    "header": {
      "allOf": [
        {
          "$ref": "shared.schema.json#/$defs/resourceHeaderBase"
        },
        {
          "type": "object",
          "required": [
            "id"
          ],
          "properties": {
            "kind": {
              "const": "flow"
            }
          }
        }
      ]
    },
    "body": {
      "allOf": [
        {
          "$ref": "shared.schema.json#/$defs/auditFields"
        },
        {
          "type": "object",
          "required": [
            "nome",
            "load_type",
            "nodes"
          ],
          "properties": {
            "nome": {
              "type": "string",
              "minLength": 1
            },
            "_state": {
              "$ref": "shared.schema.json#/$defs/readOnlyState"
            },
            "load_type": {
              "$ref": "shared.schema.json#/$defs/loadType"
            },
            "load_type_column": {
              "type": [
                "string",
                "null"
              ]
            },
            "write_mode": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "replace_all",
                "replace_window",
                "upsert_by_key",
                "insert_only",
                null
              ],
              "description": "Axis 2 of the load, the write mode: what happens in the destination to what the extraction brought. replace_all deletes everything before inserting; replace_window deletes the window and needs load_type_column; upsert_by_key overwrites the row with the same key and requires key_type unique with key_columns on a table_type=table destination; insert_only only appends, and is refused on a destination that already deduplicates. replace_all and replace_window are the only ones that notice a record deleted at the source. null or absent = derived from load_type plus the destination's key_type, which is how every flow written before this field runs. Only five of the twelve combinations with load_type are valid: `lumo lint` refuses the ones that would corrupt data, and names which of the two fields to change."
            },
            "key_sweep": {
              "type": [
                "object",
                "null"
              ],
              "description": "Deletion sync (\"varredura de exclusões\"): a query returning ONLY the keys still present in the source. A schedule entry with context=KeySweep runs it and marks as deleted, in the destination table, every row whose key did not come back. null (or absent) means no sweep is configured. Only valid on load_type=Incremental whose destination is a table_type=table with key_type=unique and key_columns set - the delete mark is a Doris unique-model concept, and without a key it would add a dead row beside the live one instead of replacing it. The query is refused by the server unless it is read-only; `lumo lint` checks the shape, the server owns the SQL safety check.",
              "required": [
                "sql",
                "credentialId"
              ],
              "properties": {
                "sql": {
                  "type": "string",
                  "minLength": 1,
                  "description": "SELECT returning only the key columns, in the same order and type as the destination's key_columns. A mismatched key format is silently catastrophic (VARCHAR vs INT, trailing spaces, different case), so test it in the web editor before scheduling."
                },
                "credentialId": {
                  "$ref": "shared.schema.json#/$defs/id",
                  "description": "Credential used to run the key query. Its own field rather than the flow extractor's: the query needs nothing beyond read access, and a read-only credential is the real defense here."
                }
              },
              "additionalProperties": false
            },
            "deskId": {
              "$ref": "shared.schema.json#/$defs/readOnlyDeskId"
            },
            "cloned_from": {
              "$ref": "shared.schema.json#/$defs/readOnlyClonedFrom"
            },
            "originalTableId": {
              "$ref": "shared.schema.json#/$defs/readOnlyOriginalTableId"
            },
            "version": {
              "$ref": "shared.schema.json#/$defs/readOnlyVersion"
            },
            "tokenId": {
              "$ref": "shared.schema.json#/$defs/nullableId",
              "description": "Editable canonical agent/token assignment for this flow."
            },
            "development_variables": {
              "type": "array",
              "items": {
                "$ref": "shared.schema.json#/$defs/jsonValue"
              }
            },
            "nodes": {
              "type": "object",
              "required": [
                "Connections",
                "Processors"
              ],
              "properties": {
                "Connections": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "from",
                      "to"
                    ],
                    "properties": {
                      "from": {
                        "type": "string"
                      },
                      "to": {
                        "type": "string"
                      }
                    },
                    "additionalProperties": true
                  }
                },
                "Processors": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "internalId",
                      "kind"
                    ],
                    "properties": {
                      "complete_id": {
                        "type": "string"
                      },
                      "internalId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "kind": {
                        "type": "string",
                        "minLength": 1
                      },
                      "description": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "inputs": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "metadata": {
                        "$ref": "shared.schema.json#/$defs/freeformObject"
                      },
                      "options": {
                        "$ref": "shared.schema.json#/$defs/freeformObject"
                      },
                      "x": {
                        "type": "number"
                      },
                      "y": {
                        "type": "number"
                      }
                    },
                    "additionalProperties": true
                  }
                }
              },
              "additionalProperties": true
            },
            "table": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "id": {
                  "$ref": "shared.schema.json#/$defs/id"
                },
                "nome": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            },
            "tags": {
              "$ref": "shared.schema.json#/$defs/tagList"
            },
            "owners": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "userId": {
                    "$ref": "shared.schema.json#/$defs/id"
                  }
                },
                "additionalProperties": true
              }
            }
          },
          "additionalProperties": true
        }
      ]
    }
  },
  "additionalProperties": false
}
