{
  "$id": "https://uape.dev/schemas/gateway-1.0.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Gateway Binding",
  "description": "How a module exposes itself through a gateway crate.",
  "type": "object",
  "additionalProperties": false,
  "required": ["kind", "binding"],
  "properties": {
    "kind": {
      "type": "string",
      "enum": ["telegram-tma", "grpc", "http"]
    },
    "binding": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["command"],
          "properties": {
            "command": { "type": "string", "pattern": "^/[a-z][a-z0-9_-]{0,31}$" },
            "webapp_route": { "type": "string", "pattern": "^/[A-Za-z0-9/_-]{1,128}$" },
            "description": { "type": "string", "maxLength": 256 }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["service", "method"],
          "properties": {
            "service": { "type": "string", "pattern": "^[a-z][a-z0-9.]*$" },
            "method":  { "type": "string", "pattern": "^[A-Z][A-Za-z0-9]+$" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["path", "method"],
          "properties": {
            "path":   { "type": "string", "pattern": "^/[A-Za-z0-9/_-]{0,255}$" },
            "method": { "type": "string", "enum": ["GET", "POST", "PUT", "DELETE", "PATCH"] }
          }
        }
      ]
    },
    "rate_limit": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "rps":   { "type": "integer", "minimum": 1, "maximum": 10000 },
        "burst": { "type": "integer", "minimum": 1, "maximum": 100000 }
      }
    },
    "auth": {
      "type": "string",
      "enum": ["telegram-initdata", "mtls", "operator-token"],
      "description": "Auth strategy enforced by the gateway before the call reaches the supervisor."
    }
  }
}
