{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/daon/json-schema/daon-archive-process-instances-request-schema.json",
  "title": "ArchiveProcessInstancesRequest",
  "description": "Batch archive submission request.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/daon-process-instance-archiving-api-openapi.yml#/components/schemas/ArchiveProcessInstancesRequest",
  "type": "object",
  "properties": {
    "archivePolicyName": {
      "type": "string",
      "description": "Name of an existing archive policy for the tenant.",
      "minLength": 1
    },
    "archivePolicyVersion": {
      "type": "integer",
      "format": "int32",
      "description": "Version of the archive policy."
    },
    "filter": {
      "$ref": "#/$defs/ArchiveFilter",
      "description": "Selector describing which process instances to archive."
    },
    "archiveKey": {
      "type": "string",
      "description": "Key used to derive the unique archive-tmp path passed to the archive policy's cloud function. Applied to every instance in the batch. Required when the archive policy has a cloud function configured; ignored otherwise. May only contain letters, digits, '_' and '-' (max 128 chars) so it forms a single, safe S3 path segment.",
      "maxLength": 128,
      "minLength": 0,
      "pattern": "^[A-Za-z0-9_-]+$"
    }
  },
  "required": [
    "archivePolicyName",
    "archivePolicyVersion",
    "filter"
  ],
  "$defs": {
    "ArchiveFilter": {
      "type": "object",
      "description": "Selector describing which process instances to archive.",
      "oneOf": [
        {
          "$ref": "#/$defs/DateFilter"
        },
        {
          "$ref": "#/$defs/IdFilter"
        }
      ],
      "properties": {
        "filterType": {
          "type": "string",
          "description": "Discriminator selecting the concrete filter type.",
          "enum": [
            "date",
            "id"
          ],
          "minLength": 1
        }
      },
      "required": [
        "filterType"
      ]
    },
    "DateFilter": {
      "allOf": [
        {
          "$ref": "#/$defs/ArchiveFilter"
        },
        {
          "type": "object",
          "properties": {
            "createdDtmFrom": {
              "type": "string",
              "format": "date-time",
              "description": "Inclusive lower bound of the process instance createdDtm."
            },
            "createdDtmTo": {
              "type": "string",
              "format": "date-time",
              "description": "Inclusive upper bound of the process instance createdDtm."
            },
            "processDefinitionId": {
              "type": "string",
              "description": "Process definition id. Mutually exclusive with processDefinitionName."
            },
            "processDefinitionName": {
              "type": "string",
              "description": "Process definition name. Mutually exclusive with processDefinitionId."
            },
            "processDefinitionVersion": {
              "type": "integer",
              "format": "int32",
              "description": "Process definition version. Only valid with processDefinitionName; all versions match when omitted."
            }
          }
        }
      ],
      "description": "Selects process instances by created-date range and process definition.",
      "required": [
        "createdDtmFrom",
        "createdDtmTo",
        "filterType"
      ]
    },
    "IdFilter": {
      "allOf": [
        {
          "$ref": "#/$defs/ArchiveFilter"
        },
        {
          "type": "object",
          "properties": {
            "processInstanceIds": {
              "type": "array",
              "description": "Explicit list of process instance ids to archive.",
              "items": {
                "type": "string"
              },
              "minItems": 1
            }
          }
        }
      ],
      "description": "Selects process instances by explicit ids. Documented only ? not yet implemented.",
      "required": [
        "filterType",
        "processInstanceIds"
      ]
    }
  }
}