post:
  operationId: createWorkflow
  tags:
    - Workflows
  summary: Create Workflow
  description: >-
    Create a new workflow with the desired trigger and steps specified in the request body.
  security:
    - oauth2: [sp:workflow:manage]
  requestBody:
    required: true
    content:
      application/json:
        schema:
          allOf:
          - required:
            - name
            - owner
          - $ref: '../schemas/WorkflowBody.yaml'
        examples:
          Event Trigger:
            description: Workflow initiated by an event trigger
            value:
              name: Send Email
              owner:
                type: IDENTITY
                id: 2c91808568c529c60168cca6f90c1313
                name: William Wilson
              description: Send an email to the identity who's attributes changed.
              definition:
                start: Send Email Test
                steps:
                  Send Email:
                    actionId: sp:send-email
                    attributes:
                      body: This is a test
                      from: sailpoint@sailpoint.com
                      recipientId.$: "$.identity.id"
                      subject: test
                    nextStep: success
                    selectResult:
                    type: action
                  success:
                    type: success
              enabled: false
              trigger:
                type: EVENT
                attributes:
                  id: idn:identity-attributes-changed
                  filter: "$.changes[?(@.attribute == 'manager')]" 
          Scheduled Trigger:
            description: Workflow initiated by a scheduled trigger
            value:
              name: Send Email
              owner:
                type: IDENTITY
                id: 2c91808568c529c60168cca6f90c1313
                name: William Wilson
              description: Send an email to the identity who's attributes changed.
              definition:
                start: Send Email Test
                steps:
                  Send Email:
                    actionId: sp:send-email
                    attributes:
                      body: This is a test
                      from: sailpoint@sailpoint.com
                      recipientId.$: "$.identity.id"
                      subject: test
                    nextStep: success
                    selectResult:
                    type: action
                  success:
                    type: success
              enabled: false
              trigger:
                type: SCHEDULED
                attributes:
                  cronString: 0 * */3 */5 *
          # External Trigger:
          #   description: Workflow initiated by an external trigger
          #   value:
          #     name: Send Email
          #     owner:
          #       type: IDENTITY
          #       id: 2c91808568c529c60168cca6f90c1313
          #       name: William Wilson
          #     description: Send an email to the identity who's attributes changed.
          #     definition:
          #       start: Send Email Test
          #       steps:
          #         Send Email:
          #           actionId: sp:send-email
          #           attributes:
          #             body: This is a test
          #             from: sailpoint@sailpoint.com
          #             recipientId.$: "$.identity.id"
          #             subject: test
          #           nextStep: success
          #           selectResult:
          #           type: action
          #         success:
          #           type: success
          #     enabled: false
          #     trigger:
          #       type: EXTERNAL
          #       attributes:
          #         name: search-and-notify
          #         description: Run a search and notify the results
  responses:
    '200':
      description: The Workflow object
      content:
        application/json:
          schema:
            $ref: '../schemas/Workflow.yaml'
    '400':
      $ref: '../../v3/responses/400.yaml'
    '401':
      $ref: '../../v3/responses/401.yaml'
    '403':
      $ref: '../../v3/responses/403.yaml'
    '429':
      $ref: '../../v3/responses/429.yaml'
    '500':
      $ref: '../../v3/responses/500.yaml'
get:
  operationId: listWorkflows
  tags:
    - Workflows
  summary: List Workflows
  description: >-
    List all workflows in the tenant.
  security:
    - oauth2: [sp:workflow:read]
  responses:
    '200':
      description: >-
        List of workflows
      content:
        application/json:
          schema:
            type: array
            items:
              $ref: '../schemas/Workflow.yaml'
    '400':
      $ref: '../../v3/responses/400.yaml'
    '401':
      $ref: '../../v3/responses/401.yaml'
    '403':
      $ref: '../../v3/responses/403.yaml'
    '429':
      $ref: '../../v3/responses/429.yaml'
    '500':
      $ref: '../../v3/responses/500.yaml'
