post:
  operationId: spConfigImport
  # security:
  #   - oauth2: [sp:config:import]
  tags:
    - SP-Config
  summary: Initiates Configuration Objects Import Job.
  description: >-
    This post will import objects from a JSON configuration file into a tenant.

    Request will need the following security scope:

    'sp:config:import'
  parameters:
    - in: query
      name: preview
      schema:
        type: boolean
        default: false
      required: false
      description: >-
        This option is intended to give the user information about how an import operation would proceed, without
        having any affect on the target tenant.
        If true, no objects will be imported. Instead, the import process will pre-process the import file and
        attempt to resolve references within imported objects. The import result file will contain messages
        pertaining to how specific references were resolved, any errors associated with the preprocessing,
        and messages indicating which objects would be imported.
      example: "true"
  requestBody:
    description: |
      The form-data "name" attribute for the file content must be "data".

      __Example__

          data: "config_export_0340b957-5caa-44f6-ada2-d3c4c5bd0b19.json",
          options: {
            "excludeTypes": [],
            "includeTypes": ["TRIGGER_SUBSCRIPTION"],
            "objectOptions": {
              "TRIGGER_SUBSCRIPTION": {
                "includedIds": [ "193446a1-c431-4326-8ba7-d6eebf922948"],
                "includedNames":[]
              }
            },
            "defaultReferences": [
              {
                "type": "TRIGGER_SUBSCRIPTION",
                "id": "be9e116d-08e1-49fc-ab7f-fa585e96c9e4",
                "name": "Test Trigger"
              }
            ]
          }

      __Sample Import File__

          {
          	"version": 1,
          	"timestamp": "2021-05-10T15:19:23.425041-05:00",
          	"tenant": "sampleTenant",
          	"options": {
          		"excludeTypes": [],
          		"includeTypes": ["TRIGGER_SUBSCRIPTION"],
          		"objectOptions": null
          	},
          	"objects": [{
          			"version": 1,
          			"self": {
          				"type": "TRIGGER_SUBSCRIPTION",
          				"name": "test trigger",
          				"id": "193446a1-c431-4326-8ba7-d6eebf922948"
          			},
          			"object": {
          				"type": "HTTP",
          				"enabled": true,
          				"httpConfig": {
          					"url": "https://localhost",
          					"httpAuthenticationType": "NO_AUTH",
          					"basicAuthConfig": null,
          					"bearerTokenAuthConfig": null,
          					"httpDispatchMode": "SYNC"
          				},
          				"triggerName": "Access Request Submitted",
          				"responseDeadline": "PT1H",
          				"name": "test trigger",
          				"triggerId": "idn:access-request-pre-approval"
          			}
          		}
          	]
          }

    required: true
    content:
      multipart/form-data:
        schema:
          type: object
          properties:
            data:
              type: string
              description: Name of JSON file containing the objects to be imported.
            options:
              $ref: '../../beta/schemas/ImportOptions.yaml'
          required:
            - data
        # Redoc does not support rendering examples for multipart/form-data yet.
        # Including it anyway for documentation.
        example: {
          data: "config_export_0340b957-5caa-44f6-ada2-d3c4c5bd0b19.json",
          options: {
            "excludeTypes": [],
            "includeTypes": ["TRIGGER_SUBSCRIPTION"],
            "objectOptions": {
              "TRIGGER_SUBSCRIPTION": {
                "includedIds": [ "be9e116d-08e1-49fc-ab7f-fa585e96c9e4"],
                "includedNames":["Lori Test 2"]
              }
            },
            "defaultReferences": [
              {
                "type": "TRIGGER_SUBSCRIPTION",
                "id": "be9e116d-08e1-49fc-ab7f-fa585e96c9e4",
                "name": "Test Trigger"
              }
            ]
          }
        }
  responses:
    '202':
      description: >-
        Import job accepted and queued for processing.
      content:
        application/json:
          schema:
            $ref: '../schemas/SpConfigJob.yaml'
    '400':
      description: |
        Client Error - Returned if the request body is invalid.
      content:
        application/json:
          schema:
            $ref: '../../v3/schemas/ErrorResponseDto.yaml'
    '401':
      $ref: '../../v3/responses/401.yaml'
    '403':
      $ref: '../../v3/responses/403.yaml'
    '404':
      $ref: '../../v3/responses/404.yaml'
    '429':
      $ref: '../../v3/responses/429.yaml'
    '500':
      $ref: '../../v3/responses/500.yaml'
