{
  "openapi": "3.1.0",
  "info": {
    "title": "WTP Developer API",
    "version": "6.0.0"
  },
  "servers": [
    {
      "url": "https://your-server.example",
      "description": "Production placeholder; deployment must be configured separately"
    },
    {
      "url": "http://localhost:3000",
      "description": "Local development only"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "paths": {
    "/api/v1/messages/text": {
      "post": {
        "summary": "Send Text",
        "operationId": "send-text",
        "description": "Required scope: messages:send",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "messageId",
                    "queueId",
                    "status",
                    "replayed"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "messageId": {
                      "type": "string"
                    },
                    "queueId": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string"
                    },
                    "replayed": {
                      "type": "boolean"
                    },
                    "sessionId": {
                      "type": "string",
                      "description": "Owned WhatsApp session used for this message"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "messageId": "WHATSAPP_MESSAGE_ID",
                  "queueId": 123,
                  "status": "queued",
                  "replayed": false
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Reference or idempotency conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Reference or idempotency conflict"
                  }
                }
              }
            }
          },
          "413": {
            "description": "File too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "File too large"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          },
          "503": {
            "description": "Stopping",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Stopping"
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "to",
                  "message"
                ],
                "properties": {
                  "to": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4096
                  },
                  "referenceId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          },
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ]
      }
    },
    "/api/v1/messages/image": {
      "post": {
        "summary": "Send Image",
        "operationId": "send-image",
        "description": "Required scope: messages:send",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "messageId",
                    "queueId",
                    "status",
                    "replayed"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "messageId": {
                      "type": "string"
                    },
                    "queueId": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string"
                    },
                    "replayed": {
                      "type": "boolean"
                    },
                    "sessionId": {
                      "type": "string",
                      "description": "Owned WhatsApp session used for this message"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "messageId": "WHATSAPP_MESSAGE_ID",
                  "queueId": 123,
                  "status": "queued",
                  "replayed": false
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Reference or idempotency conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Reference or idempotency conflict"
                  }
                }
              }
            }
          },
          "413": {
            "description": "File too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "File too large"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          },
          "503": {
            "description": "Stopping",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Stopping"
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "to",
                  "file"
                ],
                "properties": {
                  "to": {
                    "type": "string"
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 4096
                  },
                  "referenceId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          },
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ]
      }
    },
    "/api/v1/messages/document": {
      "post": {
        "summary": "Send PDF",
        "operationId": "send-document",
        "description": "Required scope: messages:send",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "messageId",
                    "queueId",
                    "status",
                    "replayed"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "messageId": {
                      "type": "string"
                    },
                    "queueId": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string"
                    },
                    "replayed": {
                      "type": "boolean"
                    },
                    "sessionId": {
                      "type": "string",
                      "description": "Owned WhatsApp session used for this message"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "messageId": "WHATSAPP_MESSAGE_ID",
                  "queueId": 123,
                  "status": "queued",
                  "replayed": false
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Reference or idempotency conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Reference or idempotency conflict"
                  }
                }
              }
            }
          },
          "413": {
            "description": "File too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "File too large"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          },
          "503": {
            "description": "Stopping",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Stopping"
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "to",
                  "file"
                ],
                "properties": {
                  "to": {
                    "type": "string"
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 4096
                  },
                  "referenceId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "fileName": {
                    "type": "string"
                  },
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          },
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ]
      }
    },
    "/api/v1/messages/{id}": {
      "get": {
        "summary": "Get Message",
        "operationId": "get-message",
        "description": "Required scope: messages:read",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "message": {
                    "id": "123",
                    "whatsappMessageId": "WHATSAPP_MESSAGE_ID",
                    "to": "937XXXXXXXX",
                    "direction": "outgoing",
                    "type": "text",
                    "message": "Hello",
                    "status": "queued",
                    "referenceId": "order-1001",
                    "sourceApplication": "My App",
                    "createdAt": "2026-09-16T10:00:00.000Z",
                    "sentAt": null,
                    "deliveredAt": null,
                    "readAt": null,
                    "error": null
                  }
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ]
      }
    },
    "/api/v1/messages/reference/{referenceId}": {
      "get": {
        "summary": "Lookup Reference",
        "operationId": "get-reference",
        "description": "Required scope: messages:read",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "message"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "$ref": "#/components/schemas/Message"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "message": {
                    "id": "123",
                    "whatsappMessageId": "WHATSAPP_MESSAGE_ID",
                    "to": "937XXXXXXXX",
                    "direction": "outgoing",
                    "type": "text",
                    "message": "Hello",
                    "status": "queued",
                    "referenceId": "order-1001",
                    "sourceApplication": "My App",
                    "createdAt": "2026-09-16T10:00:00.000Z",
                    "sentAt": null,
                    "deliveredAt": null,
                    "readAt": null,
                    "error": null
                  }
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "referenceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ]
      }
    },
    "/api/v1/messages": {
      "get": {
        "summary": "List Messages",
        "operationId": "list-messages",
        "description": "Required scope: messages:read; own outgoing messages only. incoming returns empty; use webhooks for inbound.",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "items",
                        "page",
                        "limit",
                        "total",
                        "pages"
                      ],
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Message"
                          }
                        },
                        "page": {
                          "type": "integer"
                        },
                        "limit": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        },
                        "pages": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "success": true,
                  "data": {
                    "items": [],
                    "page": 1,
                    "limit": 20,
                    "total": 0,
                    "pages": 0
                  }
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000000
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "queued",
                "processing",
                "sent",
                "delivered",
                "read",
                "failed",
                "cancelled"
              ]
            }
          },
          {
            "in": "query",
            "name": "direction",
            "schema": {
              "type": "string",
              "enum": [
                "incoming",
                "outgoing"
              ]
            }
          },
          {
            "in": "query",
            "name": "type",
            "schema": {
              "type": "string",
              "enum": [
                "text",
                "image",
                "document"
              ]
            }
          },
          {
            "in": "query",
            "name": "phone",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "dateFrom",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "in": "query",
            "name": "dateTo",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ]
      }
    },
    "/api/v1/session/status": {
      "get": {
        "summary": "Session Status",
        "operationId": "session-status",
        "description": "Required scope: session:read",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "status",
                        "phone",
                        "lastConnected"
                      ],
                      "properties": {
                        "status": {
                          "type": "string"
                        },
                        "phone": {
                          "type": "string"
                        },
                        "lastConnected": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                },
                "example": {
                  "success": true,
                  "data": {
                    "status": "connected",
                    "phone": "937XXXXXXXX",
                    "lastConnected": null
                  }
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ]
      }
    },
    "/api/v1/status": {
      "get": {
        "summary": "API Status",
        "operationId": "status",
        "description": "Required scope: session:read",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "apiVersion",
                        "whatsapp"
                      ],
                      "properties": {
                        "apiVersion": {
                          "type": "string"
                        },
                        "whatsapp": {
                          "type": "string"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "success": true,
                  "data": {
                    "apiVersion": "v1",
                    "whatsapp": "connected"
                  }
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ]
      }
    },
    "/api/send": {
      "post": {
        "summary": "Send Text",
        "operationId": "legacy-send",
        "description": "Required scope: messages:send",
        "responses": {
          "200": {
            "description": "Success; sending means queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "messageId",
                    "queueId",
                    "status",
                    "replayed"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "messageId": {
                      "type": "string"
                    },
                    "queueId": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string"
                    },
                    "replayed": {
                      "type": "boolean"
                    },
                    "sessionId": {
                      "type": "string",
                      "description": "Owned WhatsApp session used for this message"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "messageId": "WHATSAPP_MESSAGE_ID",
                  "queueId": 123,
                  "status": "queued",
                  "replayed": false
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid input"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Invalid key"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Missing scope"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Not found"
                  }
                }
              }
            }
          },
          "409": {
            "description": "Reference or idempotency conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Reference or idempotency conflict"
                  }
                }
              }
            }
          },
          "413": {
            "description": "File too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "File too large"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Rate limit"
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds before retry"
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Server error"
                  }
                }
              }
            }
          },
          "503": {
            "description": "Stopping",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "success": false,
                  "error": {
                    "code": "REQUEST_FAILED",
                    "message": "Stopping"
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "to",
                  "message"
                ],
                "properties": {
                  "to": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4096
                  },
                  "referenceId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          },
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ],
        "deprecated": true
      }
    },
    "/api/auth/register": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/auth/register",
        "description": "All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name",
                  "email",
                  "password",
                  "confirmPassword"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  },
                  "password": {
                    "type": "string",
                    "minLength": 12,
                    "description": "Maximum 72 UTF-8 bytes",
                    "writeOnly": true
                  },
                  "confirmPassword": {
                    "type": "string",
                    "writeOnly": true
                  },
                  "company": {
                    "type": "string",
                    "maxLength": 120
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/profile": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/profile",
        "description": "All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      },
      "put": {
        "x-platform": true,
        "summary": "PUT /api/profile",
        "description": "Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "company": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "currentPassword": {
                    "type": "string",
                    "writeOnly": true
                  },
                  "newPassword": {
                    "type": "string",
                    "writeOnly": true,
                    "minLength": 12
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sessions": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/sessions",
        "description": "All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      },
      "post": {
        "x-platform": true,
        "summary": "POST /api/sessions",
        "description": "Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sessions/{id}": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/sessions/{id}",
        "description": "All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "put": {
        "x-platform": true,
        "summary": "PUT /api/sessions/{id}",
        "description": "Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "x-platform": true,
        "summary": "DELETE /api/sessions/{id}",
        "description": "Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "confirmation": {
                    "type": "string",
                    "const": "REMOVE WHATSAPP SESSION"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sessions/{id}/default": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/sessions/{id}/default",
        "description": "Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/sessions/{id}/restart": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/sessions/{id}/restart",
        "description": "Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/sessions/{id}/reconnect": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/sessions/{id}/reconnect",
        "description": "Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/sessions/{id}/disconnect": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/sessions/{id}/disconnect",
        "description": "Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/sessions": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/v1/sessions",
        "description": "All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": []
      }
    },
    "/api/v1/sessions/{id}": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/v1/sessions/{id}",
        "description": "All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/usage": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/usage",
        "description": "All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      }
    },
    "/api/admin/users": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/admin/users",
        "description": "SUPER_ADMIN only. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      }
    },
    "/api/admin/users/{id}": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/admin/users/{id}",
        "description": "SUPER_ADMIN only. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/admin/users/{id}/approve": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/admin/users/{id}/approve",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/admin/users/{id}/reject": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/admin/users/{id}/reject",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/admin/users/{id}/suspend": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/admin/users/{id}/suspend",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/admin/users/{id}/reactivate": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/admin/users/{id}/reactivate",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/admin/users/{id}/limits": {
      "put": {
        "x-platform": true,
        "summary": "PUT /api/admin/users/{id}/limits",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "maxSessions": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1,
                    "maximum": 10
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/settings": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/admin/settings",
        "description": "SUPER_ADMIN only. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      },
      "put": {
        "x-platform": true,
        "summary": "PUT /api/admin/settings",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "max_users": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "default_max_sessions": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "absolute_max_sessions": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "api_limit_per_minute": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "max_running_sessions": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/audit": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/admin/audit",
        "description": "SUPER_ADMIN only. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      }
    },
    "/api/admin/overview": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/admin/overview",
        "description": "SUPER_ADMIN only. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      }
    },
    "/api/admin/health": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/admin/health",
        "description": "SUPER_ADMIN only. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      }
    },
    "/api/admin/sessions": {
      "get": {
        "x-platform": true,
        "summary": "GET /api/admin/sessions",
        "description": "SUPER_ADMIN only. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": []
      }
    },
    "/api/admin/sessions/{id}/disconnect": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/admin/sessions/{id}/disconnect",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "confirmation": {
                    "type": "string",
                    "const": "CONFIRM SESSION ACTION"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/sessions/{id}/suspend": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/admin/sessions/{id}/suspend",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "confirmation": {
                    "type": "string",
                    "const": "CONFIRM SESSION ACTION"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/sessions/{id}/resume": {
      "post": {
        "x-platform": true,
        "summary": "POST /api/admin/sessions/{id}/resume",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "confirmation": {
                    "type": "string",
                    "const": "CONFIRM SESSION ACTION"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/maintenance": {
      "put": {
        "x-platform": true,
        "summary": "PUT /api/admin/maintenance",
        "description": "SUPER_ADMIN only. Requires X-CSRF-Token from dashboard login for mutations. All resources are owner-scoped. Cross-owner IDs return 404.",
        "responses": {
          "200": {
            "description": "Success JSON envelope"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Account status, role or CSRF denied"
          },
          "404": {
            "description": "Resource not found"
          }
        },
        "security": [
          {
            "DashboardCookie": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "DashboardCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "wtp_session"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "success",
          "error"
        ],
        "properties": {
          "success": {
            "const": false
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "whatsappMessageId": {
            "type": [
              "string",
              "null"
            ]
          },
          "to": {
            "type": "string"
          },
          "direction": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "referenceId": {
            "type": [
              "string",
              "null"
            ]
          },
          "sourceApplication": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "sentAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "readAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "parameters": {
      "SessionId": {
        "name": "X-WTP-Session-ID",
        "in": "header",
        "required": false,
        "description": "Owned WhatsApp session ID. Required unless an explicit owned default is configured. Legacy owner retains its migrated default. Invalid or foreign IDs are rejected.",
        "schema": {
          "type": "string",
          "pattern": "^wts_[a-f0-9]{32}$"
        }
      }
    }
  }
}
