{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "operation-run-context.bulk.schema.json",
  "title": "OperationRun Context — Bulk Operation",
  "type": "object",
  "additionalProperties": true,
  "properties": {
    "operation": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "type": { "type": "string", "minLength": 1 }
      },
      "required": ["type"]
    },
    "target_scope": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "entra_tenant_id": { "type": "string", "minLength": 1 },
        "directory_context_id": { "type": "string", "minLength": 1 }
      },
      "anyOf": [
        { "required": ["entra_tenant_id"] },
        { "required": ["directory_context_id"] }
      ]
    },
    "selection": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "kind": { "type": "string", "enum": ["ids", "query"] },
        "ids_hash": { "type": "string", "minLength": 1 },
        "query_hash": { "type": "string", "minLength": 1 }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "const": "ids" } }, "required": ["kind"] },
          "then": { "required": ["ids_hash"], "not": { "required": ["query_hash"] } }
        },
        {
          "if": { "properties": { "kind": { "const": "query" } }, "required": ["kind"] },
          "then": { "required": ["query_hash"], "not": { "required": ["ids_hash"] } }
        }
      ],
      "required": ["kind"]
    },
    "idempotency": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "fingerprint": { "type": "string", "minLength": 1 }
      },
      "required": ["fingerprint"]
    }
  },
  "required": ["operation", "selection", "idempotency"]
}
