{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://photoflow.local/schemas/component-service-protocol-v1.schema.json",
  "title": "PhotoFlow Component Service Protocol V1 Envelope",
  "oneOf": [
    { "$ref": "#/$defs/request" },
    { "$ref": "#/$defs/success" },
    { "$ref": "#/$defs/failure" }
  ],
  "$defs": {
    "id": { "type": "string", "minLength": 1, "maxLength": 128 },
    "request": { "type": "object", "additionalProperties": false, "required": ["type", "id", "method", "payload", "context"], "properties": { "type": { "const": "request" }, "id": { "$ref": "#/$defs/id" }, "method": { "type": "string", "pattern": "^[a-z][a-z0-9.-]{0,119}\\.v[1-9][0-9]*$" }, "payload": { "type": "object" }, "context": { "type": "object" } } },
    "success": { "type": "object", "additionalProperties": false, "required": ["type", "id", "ok", "result"], "properties": { "type": { "const": "response" }, "id": { "$ref": "#/$defs/id" }, "ok": { "const": true }, "result": {} } },
    "failure": { "type": "object", "additionalProperties": false, "required": ["type", "id", "ok", "error", "errorCode"], "properties": { "type": { "const": "response" }, "id": { "$ref": "#/$defs/id" }, "ok": { "const": false }, "error": { "type": "string", "maxLength": 2000 }, "errorCode": { "type": "string", "pattern": "^COMPONENT_(?:HOST|SERVICE)_[A-Z_]+$" }, "retryable": { "type": "boolean" } } }
  }
}
