# key: It represents the key of the process
# string, required
# allows letters, numbers and underscores only (should start with a letter)
key: processExample1

# type: Should be "process" for processes
# required, string
type: process

# name: Describes the name of the process
# string, required
name: Start Recruitment
description: Description of the process

# summary: Describes how to display a summary of an item
# object, required
summary:

  # describes the first line (title) of the item. It can contain variables that references the fields of the tables
  # string, required
  title: "{{firstName}} {{lastName}}"

  # describes the second line (subtitle) of the item. It can contain variables that references the fields of the table.
  # string, optional
  subtitle: "{{email}}"

# icon: font-awesome icon
# string, optional
icon: person

# mainTable: Describes the table that will affect this process
# string, required
mainTable: invitation
startsFromExistingData: true

# publicStart: can be started by non-authenticated users
publicStart: false

# permissions: Defines the permissions for this process. Probably it should be moved to its own schema.
# object, optional
permissions:

  # each permission name must correspond to a valid role
  # it might reference to a role in the same app (e.g. "recruitment"), or a role in another app
  # (e.g. "anotherApp.anotherRole") or a role defined in the commons folder (e.g. "commons.employee")

  # valid values are:
  # - a boolean
  # - an object with the following optional properties:
  #   - start. It is a boolean indicating if the user can start a case of this process.
  #   - pause. Indicates if the user can pause cases. It can be:
  #     - a boolean
  #     - an object with the following optional properties
  #       - own
  #       - assigned
  #       - any
  #   - archive. Indicates if the user can archive cases. Structure is similar to pause option.

  recruiter: true # recruiter can do everything

  employee:
    start: true # can start a process
    pause:
      own: true # can pause only own cases
    archive: false # cannot archive any case

  manager:
    start: true # can start cases
    pause: true # can pause any case
    # (cannot archive cases)

# field groups allows to easily repeat fields that are common to multiple forms
# optional, object
fieldGroups:

  # they should have a key, which should follow the rules of an identifier
  # the content should match the definition of a form
  summary:

    # we can mark the whole group as readOnly
    readOnly: true

    # then we define the rows
    rows:
      - [fullName, identificationNumber]
      - education

  summaryWithScores:
    readOnly: true
    rows:
      # a row element can be a group
      - _group: summary
      # or a _title
      - _title: Scores
      # or a _statement
      - _statement: Please enter the candidate scores
      # or the fields
      - iqScore
      - englishScore
      - handsOnScore
      - [candidate, position]

# Defines the forms used by this process
# object, optional
forms:

    # The form has an id, which should follow the identification pattern
    fillOutInvitationInformation:

      # name: Determines the name of the form, string, optional. It should follow the guidelines of a name.
      # string, required
      name: Start application

      # rows: Determines the rows to be displayed in the form
      # each element can be an string, an array or an object (use the form schema to validate)
      rows:
        - candidate
        - position
        - comments

    fillOutScores:
      name: Fill out scores

      # title: Determines the title to show to the user when loooking at the task
      # It's different to the name that it accepts variables
      title: Fill out scores for {{candidate.firstName}} {{candidate.lastName}} - {{candidate.email}}

      rows:
        # a row element can be a group
        - _group: summary
        # or a _title
        - _title: Scores
        # or a _statement
        - _statement: Please enter the candidate scores
        # or the fields
        - iqScore
        - englishScore
        - handsOnScore

    manualApproval1:
      name: Manual Approval 1
      rows:
        - _group: summaryWithScores
        - approvalComments

      # a form can have outcomes. This is optional
      # object, optional
      outcomes:
        # an action has a key (that should follow the identifier pattern)
        # it can be a string (that should follow the name pattern)
        approve: Approve

        # or it can be an object, with the following attributes:
        reject:
          # title: It should be a name, required
          title: Reject

          # form: It determines the form to show when they choose this option.
          # object, optional
          # it should validate against the form schema.
          form:
            rows:
              - rejectReason

# Defines the service tasks used by this process
serviceTasks:

  # the service task has an id, which should follow the identification pattern
  calculateScore:

    # name: determines the name of the form. It should follow the guidelines of a name
    # string, optional
    name: Calculate score

    # type: Determines the type of service task.
    # string, follows the rules of an identifier
    type: httpRequest

    # retries: Number of times to retry
    # optional, number
    retries: 3

    # PROPERTIES SPECIFIC TO "httpRequest" service task

    # method: Defines the method to use
    # string, required. Can be any of GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD
    method: POST

    # url: The URL
    # string, required
    url: http://example.com/myEndpoint/{{candidate.email}}

    # query: Key/Value pairs for the query string
    # object, optional
    query:

      # the key of this object can be any text
      # the value can be any:
      # - text
      # - field - {{candidate.id}}
      # - variable - {{_vars.initiator.email}}
      # - secret - {{_secrets.mySecret}}
      # - a mix of them
      a: any text
      b: "{{candidate.id}}"
      d: "{{_secrets.mySecret}}"
      e: "{{_vars.initiator.id}}"
      f: A mix of anything {{_vars.initiator.email}} {{_secrets.abc}}

    # headers: key/value pairs of the headers to be sent to the request
    # object, optional
    headers:

      # the key of this object can be any text
      # the value can be any text, field, variable, secret or a mix of them
      Authorization: Bearer {{_secrets.myToken}}

    # Body: The body to be sent in the HTTP Request.
    # optional, can be either:
    # - a string
    # - an object
    #
    # if body is a string, it can be multiline, and can include any fields, variables, secrets.
    # body: this is the body to be sent {{candidate.id}}
    #
    # if body is an object, the object properties will be sent as form data
    body:

      myKey: myValue
      anotherKey: "{{_secrets.mySecret}}"

    # mapping: Configures how the result will be processed
    # object, optional
    mapping:

      _vars.response: "{{body}}"
      candidate.score: "{{body.data.score}}"
      _vars.statusCode: "{{statusCode}}"
      _vars.expireDate: "{{headers.expires}}"
