{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "game-video:configure-blueprint-node args",
  "description": "单节点原子整装事务。调用前先确保节点、目标节点、规则 ID、界面和组件契约已经存在；同一节点的界面、组件属性、事件响应和结算应规划完整后一次提交。",
  "type": "object",
  "additionalProperties": false,
  "required": ["nodeId"],
  "$defs": {
    "layoutValue": {
      "oneOf": [
        { "type": "number" },
        { "type": "string", "pattern": "^-?(?:[0-9]+(?:\\.[0-9]+)?|\\.[0-9]+)(?:%|px)$" }
      ]
    },
    "layout": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "top": { "$ref": "#/$defs/layoutValue" },
        "right": { "$ref": "#/$defs/layoutValue" },
        "bottom": { "$ref": "#/$defs/layoutValue" },
        "left": { "$ref": "#/$defs/layoutValue" },
        "width": { "$ref": "#/$defs/layoutValue" },
        "height": { "$ref": "#/$defs/layoutValue" },
        "translateX": { "$ref": "#/$defs/layoutValue" },
        "translateY": { "$ref": "#/$defs/layoutValue" },
        "zIndex": { "type": "number" }
      }
    },
    "numOrExpr": {
      "oneOf": [
        { "type": "number" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["expr"],
          "properties": {
            "expr": { "type": "string", "minLength": 1 },
            "pick": { "type": "object" }
          }
        }
      ]
    },
    "textValue": {
      "oneOf": [
        { "type": "string" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["ref"],
          "properties": { "ref": { "type": "string", "minLength": 1 } }
        }
      ]
    },
    "effect": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "entityId", "attr", "op", "value"],
          "properties": {
            "kind": { "const": "attr" },
            "entityId": { "type": "string", "minLength": 1 },
            "attr": { "type": "string", "minLength": 1 },
            "op": { "enum": ["add", "mul", "set"] },
            "value": { "$ref": "#/$defs/numOrExpr" },
            "once": { "type": "boolean" },
            "id": { "type": "string" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "varId", "op", "value"],
          "properties": {
            "kind": { "const": "var" },
            "varId": { "type": "string", "minLength": 1 },
            "valueType": { "enum": ["number"] },
            "op": { "enum": ["add", "mul", "set"] },
            "value": { "$ref": "#/$defs/numOrExpr" },
            "once": { "type": "boolean" },
            "id": { "type": "string" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "varId", "valueType", "op", "value"],
          "properties": {
            "kind": { "const": "var" },
            "varId": { "type": "string", "minLength": 1 },
            "valueType": { "const": "text" },
            "op": { "const": "set" },
            "value": { "$ref": "#/$defs/textValue" },
            "once": { "type": "boolean" },
            "id": { "type": "string" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "varId", "value"],
          "properties": {
            "kind": { "const": "flag" },
            "varId": { "type": "string", "minLength": 1 },
            "value": {
              "oneOf": [
                { "type": "boolean" },
                {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["ref"],
                  "properties": { "ref": { "type": "string", "pattern": "^eventPayload\\.[A-Za-z][A-Za-z0-9._-]{0,63}$" } }
                }
              ]
            },
            "id": { "type": "string" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "itemId", "op", "count"],
          "properties": {
            "kind": { "const": "item" },
            "itemId": { "type": "string", "minLength": 1 },
            "op": { "enum": ["give", "take"] },
            "count": { "$ref": "#/$defs/numOrExpr" },
            "id": { "type": "string" }
          }
        }
      ]
    },
    "spawn": {
      "type": "object",
      "additionalProperties": false,
      "required": ["overlayId", "childId"],
      "properties": {
        "overlayId": { "type": "string", "minLength": 1 },
        "childId": { "type": "string", "minLength": 1 },
        "inputs": { "type": "object" },
        "layout": { "$ref": "#/$defs/layout" },
        "ttlMs": { "type": "number", "minimum": 0 }
      }
    },
    "actions": {
      "type": "object",
      "properties": {
        "effects": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/effect" } },
        "targetNodeId": { "type": "string", "minLength": 1 },
        "edgeId": { "type": "string", "minLength": 1, "description": "blueprint.outline 已规划的精确边 ID；提供后必须与当前 nodeId/targetNodeId 端点一致。" },
        "spawns": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/spawn" } },
        "hideMountIds": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "component": {
      "type": "object",
      "additionalProperties": false,
      "required": ["childId"],
      "properties": {
        "childId": { "type": "string", "minLength": 1 },
        "inputs": { "type": "object" },
        "layout": { "$ref": "#/$defs/layout" },
        "window": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "startMs": { "type": "number", "minimum": 0 },
            "endMs": { "type": "number", "minimum": 0 }
          }
        },
        "note": { "type": "string" }
      }
    },
    "eventResponse": {
      "type": "object",
      "additionalProperties": false,
      "required": ["childId", "eventId"],
      "properties": {
        "childId": { "type": "string", "minLength": 1 },
        "eventId": { "type": "string", "minLength": 1 },
        "effects": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/effect" } },
        "targetNodeId": { "type": "string", "minLength": 1 },
        "edgeId": { "type": "string", "minLength": 1, "description": "blueprint.outline 已规划的精确边 ID。" },
        "spawns": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/spawn" } },
        "hideMountIds": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "transition": { "enum": ["immediate", "onSettlement"] },
        "routingSettlement": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["type"],
              "properties": { "type": { "const": "complete" } }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["type", "ms"],
              "properties": { "type": { "const": "at" }, "ms": { "type": "number", "minimum": 0 } }
            }
          ]
        }
      }
    },
    "interface": {
      "type": "object",
      "additionalProperties": false,
      "required": ["overlayId"],
      "properties": {
        "overlayId": { "type": "string", "minLength": 1 },
        "mountId": { "type": "string", "minLength": 1 },
        "layout": { "$ref": "#/$defs/layout" },
        "components": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/component" } },
        "eventResponses": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/eventResponse" } }
      }
    },
    "settlementTrigger": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["type", "ms"],
          "properties": { "type": { "const": "at" }, "ms": { "type": "number", "minimum": 0 } }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["type", "of"],
          "properties": {
            "type": { "const": "watch" },
            "of": { "type": "string", "minLength": 1 },
            "on": { "enum": ["change", "inc", "dec"] }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["type", "condition"],
          "properties": {
            "type": { "const": "state" },
            "condition": {
              "type": "object",
              "additionalProperties": false,
              "required": ["all"],
              "properties": { "all": { "type": "array", "items": { "type": "object" } } }
            }
          }
        }
      ]
    },
    "settlement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["trigger"],
      "properties": {
        "trigger": { "$ref": "#/$defs/settlementTrigger" },
        "effects": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/effect" } },
        "targetNodeId": { "type": "string", "minLength": 1 },
        "spawns": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/spawn" } },
        "hideMountIds": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
      }
    },
    "settlementUpdate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["settlementIndex", "trigger"],
      "properties": {
        "settlementIndex": { "type": "integer", "minimum": 0 },
        "trigger": { "$ref": "#/$defs/settlementTrigger" },
        "effects": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/effect" } },
        "targetNodeId": { "type": "string", "minLength": 1 },
        "spawns": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/spawn" } },
        "hideMountIds": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
      }
    },
    "removals": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "interfaces": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["mountId"],
            "properties": { "mountId": { "type": "string", "minLength": 1 } }
          }
        },
        "eventResponses": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["mountId", "childId", "eventId"],
            "properties": {
              "mountId": { "type": "string", "minLength": 1 },
              "childId": { "type": "string", "minLength": 1 },
              "eventId": { "type": "string", "minLength": 1 },
              "scope": { "enum": ["actions", "route", "all"], "default": "all" }
            }
          }
        },
        "eventActions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["mountId", "childId", "eventId", "actionIndex", "expectedKind"],
            "properties": {
              "mountId": { "type": "string", "minLength": 1 },
              "childId": { "type": "string", "minLength": 1 },
              "eventId": { "type": "string", "minLength": 1 },
              "actionIndex": { "type": "integer", "minimum": 0 },
              "expectedKind": { "enum": ["effect", "advance", "spawn", "hideOverlay"] }
            }
          }
        },
        "settlements": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["settlementIndex"],
            "properties": { "settlementIndex": { "type": "integer", "minimum": 0 } }
          }
        },
        "settlementActions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["settlementIndex", "actionIndex", "expectedKind"],
            "properties": {
              "settlementIndex": { "type": "integer", "minimum": 0 },
              "actionIndex": { "type": "integer", "minimum": 0 },
              "expectedKind": { "enum": ["effect", "advance", "spawn", "hideOverlay"] }
            }
          }
        },
        "edges": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["edgeId"],
            "properties": { "edgeId": { "type": "string", "minLength": 1 } }
          }
        }
      }
    }
  },
  "properties": {
    "activityRevision": {
      "type": "integer",
      "minimum": 1,
      "description": "可选的工作流代次保护；通常省略，由宿主解析当前活动 revision。"
    },
    "blueprintId": { "type": "string", "minLength": 1, "description": "目标蓝图 ID；省略时使用主蓝图。" },
    "nodeId": { "type": "string", "minLength": 1, "description": "本次聚合事务唯一允许修改的节点 ID；节点必须已经存在。" },
    "expectedRevision": {
      "type": "integer",
      "minimum": 0,
      "description": "来自 get_graph 或上一笔成功 mutation 的最新文档 revision；多节点提交时必须串行传递。"
    },
    "snapshotToken": { "type": "string", "minLength": 1 },
    "idempotencyKey": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "description": "本次完整节点事务的稳定幂等标识；相同标识不得用于不同内容。"
    },
    "interfaces": {
      "type": "array",
      "minItems": 1,
      "maxItems": 20,
      "description": "完整界面意图：界面挂载/选择、组件属性和全部事件响应一起提交，不要逐组件或逐事件拆分调用。",
      "items": { "$ref": "#/$defs/interface" }
    },
    "settlements": {
      "type": "array",
      "minItems": 1,
      "maxItems": 30,
      "description": "时间轴或条件结算及其完整动作；与同节点 interfaces 一起提交可减少工具往返。",
      "items": { "$ref": "#/$defs/settlement" }
    },
    "settlementUpdates": {
      "type": "array",
      "minItems": 1,
      "maxItems": 30,
      "description": "按结算子集序号完整替换既有时间轴或条件结算；替换时同步清理不再引用的专用连线。",
      "items": { "$ref": "#/$defs/settlementUpdate" }
    },
    "removals": {
      "description": "与节点配置面板一致的删除意图：卸载界面、删除事件响应或动作、删除结算或动作、删除节点出边。所有删除与本次其它配置一起原子提交。",
      "$ref": "#/$defs/removals"
    }
  }
}
