{
  "$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"
              ]
            },
            "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
}
