{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.apps.smartmate.io/processes/process-file.schema.json",
  "$$target": "https://schemas.apps.smartmate.io/processes/process-file.schema.json",
  "type": "object",
  "title": "Process File",
  "$$description": [
    "A process YAML file defines:",
    ",- the process properties (name, mainTable, icon, etc.).",
    ",- :ref:`forms <process-forms>`, which are referenced from user tasks.",
    ",- :ref:`field groups <field-groups>`, which are used by forms.",
    ",- :ref:`process permissions <process-permissions>`",
    ",- :ref:`service tasks <service-tasks>`"
  ],
  "required": [
    "key",
    "type",
    "name",
    "mainTable",
    "summary"
  ],
  "properties": {
    "key": {
      "$id": "#/properties/key",
      "$ref": "https://schemas.apps.smartmate.io/patterns/identification.schema.json",
      "description": "The process key. It must be unique in the app."
    },
    "type": {
      "$id": "#/properties/type",
      "type": "string",
      "enum": ["process"],
      "default": "process",
      "description": "Must be ``process``."
    },
    "name": {
      "$id": "#/properties/spec/properties/name",
      "type": "string",
      "description": "Process Name"
    },
    "description": {
      "$id": "#/properties/spec/properties/description",
      "type": "string",
      "description": "Optional Process Description."
    },
    "summary": {
      "$id": "#/properties/spec/properties/summary",
      "type": "object",
      "required": ["title"],
      "description": "Describes how to display a process instance.",
      "examples": [
        {
          "title": "Vacations request by {{_vars.initiator.firstName}} {{_vars.initiator.lastName}}",
          "subtitle": "From {{startDate}} to {{endDate}}"
        }
      ],
      "properties": {
        "title": {
          "$id": "#/properties/spec/properties/summary/properties/title",
          "type": "string",
          "description": "First line (title) of the item."
        },
        "subtitle": {
          "$id": "#/properties/spec/properties/summary/properties/subtitle",
          "type": "string",
          "description": "Second line (subtitle) of the item."
        }
      },
      "additionalProperties": false
    },
    "icon": {
      "$id": "#/properties/spec/properties/icon",
      "description": "Process icon to display for starting a process.",
      "$ref": "https://schemas.apps.smartmate.io/patterns/icon.schema.json"
    },
    "mainTable": {
      "$id": "#/properties/spec/mainTable",
      "type": "string",
      "description": ":ref:`Main table <main-table>` to be used by this process. Main table is the table where the process will store data, and where it will get the information from."
    },
    "startsFromExistingData": {
      "$id": "#/properties/spec/startsFromExistingData",
      "type": "boolean",
      "description": "Whether the process should start using data from an existing record of the main table, or if it should create a new record. See more at :ref:`Main table <main-table>` documentation."
    },
    "mainTableFilter": {
      "description": "Which records to show when starting from existing data.",
      "$ref": "https://schemas.apps.smartmate.io/tables/filter/filter.schema.json"
    },
    "publicStart": {
      "$id": "#/properties/spec/publicStart",
      "type": "boolean",
      "description": "Whether the process can be started by an anonymous user.",
      "default": false
    },
    "permissions": {
      "$id": "#/properties/spec/permissions",
      "description": "Process permissions",
      "$ref": "https://schemas.apps.smartmate.io/processes/processPermissions/processPermissions.schema.json"
    },
    "fieldGroups": {
      "$id": "#/properties/spec/fieldGroups",
      "description": ":ref:`Field groups <field-groups>` allows to easily repeat fields that are common to multiple forms",
      "type": "object",
      "propertyNames": {
        "allOf": [{
          "$ref": "https://schemas.apps.smartmate.io/patterns/identification.schema.json"
        }]
      },
      "patternProperties": {
        "": {
          "$ref": "https://schemas.apps.smartmate.io/processes/fieldGroups/fieldGroup.schema.json"
        }
      }
    },
    "forms": {
      "$id": "#/properties/spec/forms",
      "description": ":ref:`Process forms <process-forms>` used by this process",
      "propertyNames": {
        "allOf": [{
          "$ref": "https://schemas.apps.smartmate.io/patterns/identification.schema.json"
        }]
      },
      "patternProperties": {
        "": {
          "$ref": "https://schemas.apps.smartmate.io/processes/processForms/processForm.schema.json"
        }
      }
    },
    "serviceTasks": {
      "$id": "#/properties/spec/forms",
      "description": ":ref:`Service tasks <service-tasks>` used by this process",
      "propertyNames": {
        "allOf": [{
          "$ref": "https://schemas.apps.smartmate.io/patterns/identification.schema.json"
        }]
      },
      "patternProperties": {
        "": {
          "$ref": "https://schemas.apps.smartmate.io/processes/serviceTasks/serviceTask.schema.json"
        }
      }
    }
  },
  "additionalProperties": false
}
