{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://runeschema.dev/schemas/registry-patch-v1.schema.json",
  "title": "RuneSchema Registry Patch v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "modId", "patches"],
  "properties": {
    "$schema": { "type": "string" },
    "schema": { "const": "runeschema.registry-patch/v1" },
    "modId": { "$ref": "#/$defs/id" },
    "profile": { "type": "string" },
    "priority": { "type": "integer", "minimum": -100000, "maximum": 100000 },
    "patches": { "type": "array", "minItems": 1, "maxItems": 4096, "items": { "$ref": "#/$defs/patch" } }
  },
  "$defs": {
    "id": { "type": "string", "minLength": 1, "maxLength": 128, "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$" },
    "target": {
      "type": "object", "additionalProperties": false, "required": ["kind"],
      "properties": {
        "kind": { "enum": ["dataTable", "object", "classDefaultObject"] },
        "objectPath": { "type": "string" }, "shortName": { "type": "string" },
        "searchRoots": { "type": "array", "maxItems": 32, "uniqueItems": true, "items": { "type": "string" } },
        "expectedClass": { "type": "string" }, "expectedRowStruct": { "type": "string" }
      },
      "oneOf": [{ "required": ["objectPath"], "not": { "required": ["shortName"] } }, { "required": ["shortName"], "not": { "required": ["objectPath"] } }]
    },
    "patch": {
      "type": "object", "additionalProperties": false, "required": ["id", "target", "operation"],
      "properties": {
        "id": { "$ref": "#/$defs/id" }, "transaction": { "$ref": "#/$defs/id" },
        "dependsOn": { "type": "array", "maxItems": 128, "uniqueItems": true, "items": { "$ref": "#/$defs/id" } },
        "target": { "$ref": "#/$defs/target" },
        "operation": { "enum": ["addRow", "upsertOwnedRow", "copyRow", "mergeOwnedRow", "patchExistingRow", "set", "merge", "append", "appendUnique", "upsertOwned"] },
        "property": { "type": "string" }, "row": { "type": "object" }, "identity": { "type": "object" },
        "template": { "type": "object" }, "value": {}, "preconditions": { "type": "object" }
      }
    }
  }
}
