{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.apps.smartmate.io/tables/table-file.schema.json",
  "$$target": "https://schemas.apps.smartmate.io/tables/table-file.schema.json",
  "type": "object",
  "title": "Table File",
  "description": "The table YAML file define one :ref:`table <tables>` that belongs to an app.",
  "required": [
    "key",
    "type",
    "name",
    "itemName",
    "summary",
    "fields"
  ],
  "properties": {
    "key": {
      "$id": "#/properties/key",
      "$ref": "https://schemas.apps.smartmate.io/patterns/identification.schema.json",
      "description": "The table key should be unique in the app. Should start with a letter, and allow only letters and numbers."
    },
    "type": {
      "$id": "#/properties/type",
      "type": "string",
      "enum": ["table"],
      "default": "table",
      "description": "Must be ``table``"
    },
    "name": {
      "$id": "#/properties/spec/properties/name",
      "type": "string",
      "description": "Name of the table in plural. E.g. ``Candidates``"
    },
    "itemName": {
      "$id": "#/properties/spec/properties/itemName",
      "type": "string",
      "description": " Name of an item (singular). E.g. ``Candidate``"
    },
    "summary": {
      "$id": "#/properties/spec/properties/summary",
      "type": "object",
      "required": ["title"],
      "description": "Title and subtitle of an item. It will be displayed when an item from this table should be selected from another table. Both title and subtitle can contain references to fields, surrounding them in double braces.",
      "properties": {
        "title": {
          "$id": "#/properties/spec/properties/summary/properties/title",
          "type": "string",
          "description": "First line (title) of the item.",
          "examples": [
            "This is a simple title",
            "You can include fields: {{firstName}}",
            "You can include variables: {{_vars.initiator.firstName}}"
          ]
        },
        "subtitle": {
          "$id": "#/properties/spec/properties/summary/properties/subtitle",
          "type": "string",
          "description": "Second line (subtitle) of the item.",
          "examples": [
            "This is a simple subtitle",
            "You can include fields: {{firstName}}",
            "You can include variables: {{_vars.initiator.firstName}}"
          ]
          }
      },
      "additionalProperties": false
    },
    "fields": {
      "description": "Describes the :ref:`fields <table-fields>` of this table",
      "type": "object",
      "propertyNames": {
        "allOf": [{
          "$ref": "https://schemas.apps.smartmate.io/patterns/identification.schema.json",
          "examples": [
            "firstName"
          ]
        }]
      },
      "patternProperties": {
        "": {"$ref": "https://schemas.apps.smartmate.io/fields/field.schema.json"}
      }
    },
    "form": {
      "$id": "#/properties/spec/form",
      "description": "Optional. Describes this table's form. If not set, it will show all the fields.",
      "$ref": "https://schemas.apps.smartmate.io/forms/form.schema.json"
    },
    "stages": {
      "$id": "#/properties/spec/stages",
      "description": "Describe the stages that an item can go through",
      "$ref": "https://schemas.apps.smartmate.io/tables/stages/stages.schema.json"
    },
    "initialStage": {
      "$id": "#/properties/spec/initialStage",
      "description": "Indicates which of the stages should be considered by default when creating an item",
      "$ref": "https://schemas.apps.smartmate.io/patterns/identification.schema.json"
    },
    "permissions": {
      "$id": "#/properties/spec/permissions",
      "description": ":ref:`Table permissions <table-permissions>` allow users to directly view, edit or delete data from the tables, without using a process. Permissions are defined per :ref:`app role <app-roles>`, and can be very granular.",
      "$ref": "https://schemas.apps.smartmate.io/tables/tablePermissions/tablePermissions.schema.json"
    },
    "testData": {
      "$id": "#/properties/spec/testdata",
      "description": "Sample data for testing the table",
      "$ref": "https://schemas.apps.smartmate.io/tables/data/data.schema.json"
    },
    "data": {
      "$id": "#/properties/spec/data",
      "description": "Data that should be automatically populated when the app is published.",
      "$ref": "https://schemas.apps.smartmate.io/tables/data/data.schema.json"
    }
  },
  "additionalProperties": false
}
