{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.horusbi.com.br/schemas/v2/app.schema.json",
  "title": "Lumo v2 app 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": "app"
            }
          }
        }
      ]
    },
    "body": {
      "allOf": [
        {
          "$ref": "shared.schema.json#/$defs/auditFields"
        },
        {
          "type": "object",
          "required": [
            "nome",
            "config"
          ],
          "properties": {
            "nome": {
              "type": "string",
              "minLength": 1
            },
            "_state": {
              "$ref": "shared.schema.json#/$defs/readOnlyState"
            },
            "descricao": {
              "type": [
                "string",
                "null"
              ]
            },
            "icon": {
              "type": [
                "string",
                "null"
              ]
            },
            "color": {
              "$ref": "shared.schema.json#/$defs/color"
            },
            "deskId": {
              "$ref": "shared.schema.json#/$defs/readOnlyDeskId"
            },
            "version": {
              "$ref": "shared.schema.json#/$defs/readOnlyVersion"
            },
            "config": {
              "type": "object",
              "properties": {
                "show_last_loadedat": {
                  "type": "boolean"
                },
                "show_last_loadedat_tables": {
                  "type": "array",
                  "items": {
                    "$ref": "shared.schema.json#/$defs/id"
                  }
                },
                "tables": {
                  "type": "object",
                  "propertyNames": {
                    "not": {
                      "const": "undefined"
                    }
                  },
                  "additionalProperties": {
                    "$ref": "shared.schema.json#/$defs/jsonValue"
                  }
                }
              },
              "additionalProperties": true
            },
            "filtros": {
              "type": "array",
              "items": {
                "$ref": "shared.schema.json#/$defs/jsonValue"
              }
            },
            "tables": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "tableId"
                ],
                "properties": {
                  "tableId": {
                    "$ref": "shared.schema.json#/$defs/id"
                  },
                  "guid": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "nome_visualizacao": {
                    "description": "Per-app display rename ('nome de visualização' set in the DataViz table editor). SEMANTICALLY SIGNIFICANT: when set, expression and dataSource references must address the table by THIS name - [<nome_visualizacao>].\"COL\" - not the physical DW table name. Omit (or null) to keep the physical name. Setting it here renames the table for THIS app only; omitting it on push clears a previous rename (file-first).",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "tipo": {
                    "description": "App-table role. 'dimension' (default) covers every normal table - both fact tables (sales, orders) AND dimension tables (calendar, customers); the name is BI-engine legacy, NOT the star-schema concept. 'n2n' is reserved for many-to-many linking (bridge) tables. Do NOT use 'fact'/'dim'/'bridge' - server rejects.",
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "dimension",
                      "n2n",
                      null
                    ]
                  },
                  "appTableId": {
                    "$ref": "shared.schema.json#/$defs/nullableId"
                  },
                  "columns": {
                    "type": "object",
                    "description": "App-scoped per-column overlay (the DataViz 'Configurar Campos' / 'Visibilidade das Colunas'). Keyed by column_name; only columns that DIFFER from the default appear. `visible: false` hides the column from the END-USER report generator / field picker - the column stays fully usable in expressions and widgets (declutter, NOT access control). `label` overrides the column's display name for THIS app only (other apps and the DW table are unaffected). Omit a table's `columns` to leave its overlay untouched; `{}` clears every override. Draft apps only.",
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "visible": {
                          "type": "boolean"
                        },
                        "label": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                },
                "additionalProperties": true
              }
            },
            "expressions": {
              "type": "array",
              "items": {
                "$ref": "shared.schema.json#/$defs/jsonValue"
              }
            },
            "relationships": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "column_left_id",
                  "column_right_id",
                  "from_table_id",
                  "to_table_id",
                  "relationshipType"
                ],
                "properties": {
                  "id": {
                    "$ref": "shared.schema.json#/$defs/id"
                  },
                  "column_left_id": {
                    "$ref": "shared.schema.json#/$defs/id"
                  },
                  "column_right_id": {
                    "$ref": "shared.schema.json#/$defs/id"
                  },
                  "from_column": {
                    "type": "string"
                  },
                  "from_table_id": {
                    "$ref": "shared.schema.json#/$defs/id"
                  },
                  "to_column": {
                    "type": "string"
                  },
                  "to_table_id": {
                    "$ref": "shared.schema.json#/$defs/id"
                  },
                  "relationshipType": {
                    "type": "string",
                    "enum": [
                      "ONE_TO_ONE",
                      "ONE_TO_MANY",
                      "MANY_TO_ONE",
                      "MANY_TO_MANY"
                    ]
                  },
                  "ignoreTime": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": true
              }
            },
            "facts": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "nome",
                  "primaryColumn"
                ],
                "properties": {
                  "id": {
                    "$ref": "shared.schema.json#/$defs/id"
                  },
                  "nome": {
                    "type": "string",
                    "minLength": 1
                  },
                  "primaryColumn": {
                    "type": "string",
                    "pattern": "^X?\\d+(:[A-Za-z0-9_]+)+$"
                  },
                  "alternativeColumns": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "string",
                      "pattern": "^X?\\d+(:[A-Za-z0-9_]+)+$"
                    }
                  },
                  "dateColumnId": {
                    "$ref": "shared.schema.json#/$defs/nullableId"
                  },
                  "defaultDatePeriod": {
                    "$ref": "shared.schema.json#/$defs/jsonValue"
                  },
                  "filters": {
                    "type": "array",
                    "items": {
                      "$ref": "shared.schema.json#/$defs/jsonValue"
                    }
                  },
                  "prompt": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "additionalProperties": true
              }
            },
            "dynamic_dimensions": {
              "type": "array",
              "items": {
                "$ref": "shared.schema.json#/$defs/jsonValue"
              }
            },
            "tags": {
              "$ref": "shared.schema.json#/$defs/tagList"
            }
          },
          "additionalProperties": true
        }
      ]
    }
  },
  "additionalProperties": false
}
