{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/vertesiahq/json-schema/vertesiahq-bulk-operation-response-schema.json",
  "title": "BulkOperationResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/vertesiahq-bulk-operations-api-openapi.yml#/components/schemas/BulkOperationResponse",
  "oneOf": [
    {
      "$ref": "#/$defs/BulkOperationResult"
    },
    {
      "$ref": "#/$defs/BulkObjectCreateResult"
    },
    {
      "$ref": "#/$defs/BulkObjectUpdateResult"
    },
    {
      "$ref": "#/$defs/BulkObjectDeleteResult"
    }
  ],
  "type": "object",
  "required": [
    "operation"
  ],
  "$defs": {
    "BulkObjectCreateResult": {
      "type": "object",
      "properties": {
        "operation": {
          "type": "string",
          "const": "create"
        },
        "status": {
          "type": "string",
          "enum": [
            "in_progress",
            "completed",
            "failed"
          ]
        },
        "created": {
          "type": "number",
          "description": "Number of documents successfully created"
        },
        "objects": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "index": {
                "type": "number"
              },
              "external_id": {
                "type": "string"
              }
            },
            "required": [
              "id"
            ],
            "additionalProperties": false
          },
          "description": "Successfully created objects with their IDs"
        },
        "failed": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "external_id": {
                "type": "string"
              },
              "index": {
                "type": "number"
              },
              "error": {
                "type": "string"
              }
            },
            "required": [
              "index",
              "error"
            ],
            "additionalProperties": false
          },
          "description": "Objects that failed to create"
        }
      },
      "required": [
        "operation",
        "status",
        "created",
        "objects",
        "failed"
      ],
      "additionalProperties": false
    },
    "BulkObjectDeleteResult": {
      "type": "object",
      "properties": {
        "operation": {
          "type": "string",
          "const": "delete"
        },
        "status": {
          "type": "string",
          "enum": [
            "in_progress",
            "completed",
            "failed"
          ]
        },
        "deleted": {
          "type": "number",
          "description": "Number of documents deleted (including revisions)"
        },
        "failed": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "IDs that were not found or user had no permission to delete"
        }
      },
      "required": [
        "operation",
        "status",
        "deleted",
        "failed"
      ],
      "additionalProperties": false
    },
    "BulkObjectUpdateResult": {
      "type": "object",
      "properties": {
        "operation": {
          "type": "string",
          "const": "update"
        },
        "status": {
          "type": "string",
          "enum": [
            "in_progress",
            "completed",
            "failed"
          ]
        },
        "updated": {
          "type": "number",
          "description": "Number of documents successfully updated"
        },
        "failed": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "IDs that were not found, not authorized, or failed to update"
        }
      },
      "required": [
        "operation",
        "status",
        "updated",
        "failed"
      ],
      "additionalProperties": false
    },
    "BulkOperationResult": {
      "type": "object",
      "properties": {
        "operation": {
          "type": "string",
          "const": "generic"
        },
        "status": {
          "type": "string",
          "enum": [
            "in_progress",
            "completed",
            "failed"
          ]
        }
      },
      "required": [
        "operation",
        "status"
      ],
      "additionalProperties": false
    }
  }
}