{
  "openapi": "3.1.0",
  "info": {
    "title": "Avisa API",
    "version": "1.0.0",
    "summary": "API de WhatsApp para quem cria sistemas com IA.",
    "description": "API não oficial de WhatsApp (conecta como o WhatsApp Web). JSON em UTF-8, snake_case, IDs com prefixo, telefone só com dígitos e DDI. Documentação: https://avisa.dev/docs",
    "contact": {
      "name": "Avisa",
      "url": "https://avisa.dev"
    }
  },
  "externalDocs": {
    "description": "Documentação",
    "url": "https://avisa.dev/docs"
  },
  "servers": [
    {
      "url": "https://api.avisa.dev/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Numbers",
      "description": "Números de WhatsApp conectados"
    },
    {
      "name": "Messages",
      "description": "Envio e histórico de mensagens"
    },
    {
      "name": "Media",
      "description": "Arquivos de mídia"
    },
    {
      "name": "Contacts",
      "description": "Contatos"
    },
    {
      "name": "Checks",
      "description": "Verificar se telefones têm WhatsApp"
    },
    {
      "name": "Groups",
      "description": "Grupos"
    },
    {
      "name": "Webhooks",
      "description": "Webhooks e log de entregas"
    }
  ],
  "paths": {
    "/numbers": {
      "post": {
        "tags": [
          "Numbers"
        ],
        "operationId": "createNumber",
        "summary": "Criar número",
        "description": "Cria o número e devolve o QR code (ou o código de pareamento, quando `pairing_phone` é enviado).",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateNumberRequest"
              },
              "example": {
                "name": "Loja"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Número criado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NumberWithQr"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "500": {
            "$ref": "#/components/responses/E500"
          }
        }
      },
      "get": {
        "tags": [
          "Numbers"
        ],
        "operationId": "listNumbers",
        "summary": "Listar números",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de números.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Number"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Cursor da próxima página; null quando acabou."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "500": {
            "$ref": "#/components/responses/E500"
          }
        }
      }
    },
    "/numbers/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do número.",
          "schema": {
            "type": "string",
            "pattern": "^num_"
          }
        }
      ],
      "get": {
        "tags": [
          "Numbers"
        ],
        "operationId": "getNumber",
        "summary": "Obter número",
        "responses": {
          "200": {
            "description": "Número.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Number"
                },
                "example": {
                  "id": "num_8f2k1c9d",
                  "name": "Loja",
                  "phone": "5531988887777",
                  "status": "connected",
                  "plan": "monthly",
                  "billing_status": "active",
                  "trial": null,
                  "connected_at": "2026-12-04T15:01:02Z",
                  "created_at": "2026-12-04T15:00:00Z"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      },
      "delete": {
        "tags": [
          "Numbers"
        ],
        "operationId": "deleteNumber",
        "summary": "Remover número",
        "description": "Remove o número da conta e cancela a cobrança dele.",
        "responses": {
          "204": {
            "description": "Removido."
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/numbers/{id}/qr": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do número.",
          "schema": {
            "type": "string",
            "pattern": "^num_"
          }
        }
      ],
      "get": {
        "tags": [
          "Numbers"
        ],
        "operationId": "getNumberQr",
        "summary": "Obter QR code",
        "responses": {
          "200": {
            "description": "QR atual.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QrResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/numbers/{id}/reconnect": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do número.",
          "schema": {
            "type": "string",
            "pattern": "^num_"
          }
        }
      ],
      "post": {
        "tags": [
          "Numbers"
        ],
        "operationId": "reconnectNumber",
        "summary": "Reconectar",
        "description": "Gera um novo QR code.",
        "responses": {
          "200": {
            "description": "Novo QR.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QrResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "402": {
            "$ref": "#/components/responses/E402"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "502": {
            "$ref": "#/components/responses/E502"
          }
        }
      }
    },
    "/numbers/{id}/disconnect": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do número.",
          "schema": {
            "type": "string",
            "pattern": "^num_"
          }
        }
      ],
      "post": {
        "tags": [
          "Numbers"
        ],
        "operationId": "disconnectNumber",
        "summary": "Desconectar",
        "description": "Desloga do WhatsApp e mantém o número na conta.",
        "responses": {
          "200": {
            "description": "Número desconectado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Number"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "502": {
            "$ref": "#/components/responses/E502"
          }
        }
      }
    },
    "/messages": {
      "post": {
        "tags": [
          "Messages"
        ],
        "operationId": "sendMessage",
        "summary": "Enviar mensagem",
        "description": "Envia um tipo de mensagem por chamada. O tipo é escolhido pelo campo presente: text, image, video, audio, document, location, contact, poll ou reaction.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Repetir a chamada com a mesma chave em até 24 h devolve a mesma mensagem sem reenviar.",
            "schema": {
              "type": "string",
              "maxLength": 255
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendMessageRequest"
              },
              "examples": {
                "text": {
                  "value": {
                    "to": "5531999999999",
                    "text": "Oi!"
                  }
                },
                "image": {
                  "value": {
                    "to": "5531999999999",
                    "image": {
                      "url": "https://exemplo.com/a.jpg",
                      "caption": "Legenda"
                    }
                  }
                },
                "poll": {
                  "value": {
                    "to": "grp_5t7y9u1i",
                    "poll": {
                      "question": "Qual?",
                      "options": [
                        "A",
                        "B"
                      ],
                      "multiple": false
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Mensagem criada.",
            "headers": {
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimitRemaining"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                },
                "example": {
                  "id": "msg_3n9x0a7q",
                  "number_id": "num_8f2k1c9d",
                  "direction": "out",
                  "chat": {
                    "type": "contact",
                    "id": "ctc_1b6m2p4r",
                    "phone": "5531999999999",
                    "name": null
                  },
                  "from_phone": "5531988887777",
                  "type": "text",
                  "text": "Oi! Seu pedido saiu para entrega.",
                  "media": null,
                  "location": null,
                  "reply_to": null,
                  "status": "queued",
                  "error": null,
                  "sent_at": null,
                  "created_at": "2026-12-04T15:02:11Z"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "402": {
            "$ref": "#/components/responses/E402"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "500": {
            "$ref": "#/components/responses/E500"
          },
          "502": {
            "$ref": "#/components/responses/E502"
          }
        }
      },
      "get": {
        "tags": [
          "Messages"
        ],
        "operationId": "listMessages",
        "summary": "Listar mensagens",
        "description": "Histórico de mensagens, das mais novas para as mais antigas, com busca no texto.",
        "parameters": [
          {
            "name": "number_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "contact",
            "in": "query",
            "description": "Telefone do contato.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "in",
                "out"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/MessageStatus"
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Busca no texto.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de mensagens.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Cursor da próxima página; null quando acabou."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          }
        }
      }
    },
    "/messages/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id da mensagem.",
          "schema": {
            "type": "string",
            "pattern": "^msg_"
          }
        }
      ],
      "get": {
        "tags": [
          "Messages"
        ],
        "operationId": "getMessage",
        "summary": "Obter mensagem",
        "responses": {
          "200": {
            "description": "Mensagem.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                },
                "example": {
                  "id": "msg_3n9x0a7q",
                  "number_id": "num_8f2k1c9d",
                  "direction": "out",
                  "chat": {
                    "type": "contact",
                    "id": "ctc_1b6m2p4r",
                    "phone": "5531999999999",
                    "name": null
                  },
                  "from_phone": "5531988887777",
                  "type": "text",
                  "text": "Oi! Seu pedido saiu para entrega.",
                  "media": null,
                  "location": null,
                  "reply_to": null,
                  "status": "queued",
                  "error": null,
                  "sent_at": null,
                  "created_at": "2026-12-04T15:02:11Z"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/messages/{id}/read": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id da mensagem.",
          "schema": {
            "type": "string",
            "pattern": "^msg_"
          }
        }
      ],
      "post": {
        "tags": [
          "Messages"
        ],
        "operationId": "markMessageRead",
        "summary": "Marcar como lida",
        "responses": {
          "200": {
            "description": "Mensagem marcada como lida.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "502": {
            "$ref": "#/components/responses/E502"
          }
        }
      }
    },
    "/media/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id da mídia.",
          "schema": {
            "type": "string",
            "pattern": "^med_"
          }
        }
      ],
      "get": {
        "tags": [
          "Media"
        ],
        "operationId": "getMedia",
        "summary": "Baixar mídia",
        "description": "Devolve o arquivo (binário) com autenticação.",
        "responses": {
          "200": {
            "description": "Arquivo.",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "application/octet-stream"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/contacts": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "operationId": "listContacts",
        "summary": "Listar contatos",
        "parameters": [
          {
            "name": "number_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Busca por nome ou telefone.",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de contatos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Contact"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Cursor da próxima página; null quando acabou."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          }
        }
      }
    },
    "/contacts/{phone}": {
      "parameters": [
        {
          "name": "phone",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Telefone com DDI."
        },
        {
          "name": "number_id",
          "in": "query",
          "required": false,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Contacts"
        ],
        "operationId": "getContact",
        "summary": "Obter contato",
        "responses": {
          "200": {
            "description": "Contato.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          }
        }
      }
    },
    "/contacts/{phone}/photo": {
      "parameters": [
        {
          "name": "phone",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Telefone com DDI."
        }
      ],
      "get": {
        "tags": [
          "Contacts"
        ],
        "operationId": "getContactPhoto",
        "summary": "Foto de perfil",
        "responses": {
          "200": {
            "description": "URL da foto (ou null).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "url"
                  ],
                  "properties": {
                    "url": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uri"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "502": {
            "$ref": "#/components/responses/E502"
          }
        }
      }
    },
    "/checks": {
      "post": {
        "tags": [
          "Checks"
        ],
        "operationId": "checkPhones",
        "summary": "Verificar telefones",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckRequest"
              },
              "example": {
                "phones": [
                  "5531999999999"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resultado por telefone.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CheckResult"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "402": {
            "$ref": "#/components/responses/E402"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          },
          "502": {
            "$ref": "#/components/responses/E502"
          }
        }
      }
    },
    "/groups": {
      "get": {
        "tags": [
          "Groups"
        ],
        "operationId": "listGroups",
        "summary": "Listar grupos",
        "parameters": [
          {
            "name": "number_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de grupos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Group"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Cursor da próxima página; null quando acabou."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          }
        }
      },
      "post": {
        "tags": [
          "Groups"
        ],
        "operationId": "createGroup",
        "summary": "Criar grupo",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateGroupRequest"
              },
              "example": {
                "name": "Equipe Loja",
                "participants": [
                  "5531999999999"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Grupo criado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Group"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "402": {
            "$ref": "#/components/responses/E402"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "502": {
            "$ref": "#/components/responses/E502"
          }
        }
      }
    },
    "/groups/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do grupo.",
          "schema": {
            "type": "string",
            "pattern": "^grp_"
          }
        }
      ],
      "get": {
        "tags": [
          "Groups"
        ],
        "operationId": "getGroup",
        "summary": "Obter grupo",
        "description": "Inclui `participants`.",
        "responses": {
          "200": {
            "description": "Grupo com participantes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Group"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/groups/{id}/participants": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do grupo.",
          "schema": {
            "type": "string",
            "pattern": "^grp_"
          }
        }
      ],
      "post": {
        "tags": [
          "Groups"
        ],
        "operationId": "updateGroupParticipants",
        "summary": "Adicionar e remover participantes",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateParticipantsRequest"
              },
              "example": {
                "add": [
                  "5531955554444"
                ],
                "remove": [
                  "5531977776666"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Grupo atualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Group"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "502": {
            "$ref": "#/components/responses/E502"
          }
        }
      }
    },
    "/webhooks": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "createWebhook",
        "summary": "Criar webhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookRequest"
              },
              "example": {
                "url": "https://meusistema.com/webhooks/avisa",
                "events": [
                  "message.received"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook criado. O `secret` só aparece aqui.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookWithSecret"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          }
        }
      },
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "listWebhooks",
        "summary": "Listar webhooks",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de webhooks.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Webhook"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Cursor da próxima página; null quando acabou."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          }
        }
      }
    },
    "/webhooks/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do webhook.",
          "schema": {
            "type": "string",
            "pattern": "^whk_"
          }
        }
      ],
      "delete": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "deleteWebhook",
        "summary": "Remover webhook",
        "responses": {
          "204": {
            "description": "Removido."
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/webhooks/{id}/test": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do webhook.",
          "schema": {
            "type": "string",
            "pattern": "^whk_"
          }
        }
      ],
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "testWebhook",
        "summary": "Testar webhook",
        "description": "Envia um evento `webhook.test` assinado e devolve a resposta do seu servidor.",
        "responses": {
          "200": {
            "description": "Resultado do teste.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookTestResult"
                },
                "example": {
                  "status_code": 200,
                  "duration_ms": 184,
                  "body": "ok"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/webhooks/{id}/deliveries": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do webhook.",
          "schema": {
            "type": "string",
            "pattern": "^whk_"
          }
        }
      ],
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "listWebhookDeliveries",
        "summary": "Log de entregas",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Entregas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDelivery"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Cursor da próxima página; null quando acabou."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/webhooks/{id}/deliveries/{delivery_id}/retry": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id do webhook.",
          "schema": {
            "type": "string",
            "pattern": "^whk_"
          }
        },
        {
          "name": "delivery_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Id da entrega."
        }
      ],
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "retryWebhookDelivery",
        "summary": "Reenviar entrega",
        "responses": {
          "200": {
            "description": "Entrega reenviada.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDelivery"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    }
  },
  "webhooks": {
    "event": {
      "post": {
        "summary": "Evento enviado para a URL do seu webhook",
        "description": "Assinado no cabeçalho Avisa-Signature: t=<unix>,v1=<hex hmac_sha256(secret, \"<t>.<corpo>\")>. Responda 2xx em até 10 s. Retentativas: 1 min, 5 min, 30 min, 2 h, 6 h, 24 h.",
        "parameters": [
          {
            "name": "Avisa-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^t=\\d+,v1=[0-9a-f]{64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Recebido."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "av_live_<32>",
        "description": "Chave de API: Authorization: Bearer av_live_..."
      }
    },
    "parameters": {
      "limit": {
        "name": "limit",
        "in": "query",
        "required": false,
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 50
        }
      },
      "cursor": {
        "name": "cursor",
        "in": "query",
        "required": false,
        "schema": {
          "type": "string"
        }
      }
    },
    "headers": {
      "RateLimitRemaining": {
        "description": "Envios restantes na janela atual.",
        "schema": {
          "type": "integer"
        }
      },
      "RetryAfter": {
        "description": "Segundos até poder tentar de novo.",
        "schema": {
          "type": "integer"
        }
      }
    },
    "responses": {
      "E401": {
        "description": "Chave ausente, inválida ou revogada.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unauthorized",
                "message": "Chave ausente, inválida ou revogada.",
                "docs_url": "https://avisa.dev/docs/errors#unauthorized"
              }
            }
          }
        }
      },
      "E403": {
        "description": "A chave não tem acesso a este recurso.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "forbidden",
                "message": "A chave não tem acesso a este recurso.",
                "docs_url": "https://avisa.dev/docs/errors#forbidden"
              }
            }
          }
        }
      },
      "E404": {
        "description": "O recurso não existe.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "not_found",
                "message": "O recurso não existe.",
                "docs_url": "https://avisa.dev/docs/errors#not_found"
              }
            }
          }
        }
      },
      "E409": {
        "description": "O número não está conectado (ou number_limit: limite de números atingido).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "number_not_connected",
                "message": "O número não está conectado (ou number_limit: limite de números atingido).",
                "docs_url": "https://avisa.dev/docs/errors#number_not_connected"
              }
            }
          }
        }
      },
      "E402": {
        "description": "Sem plano ativo (ou trial_limit: teste grátis acabou).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "payment_required",
                "message": "Sem plano ativo (ou trial_limit: teste grátis acabou).",
                "docs_url": "https://avisa.dev/docs/errors#payment_required"
              }
            }
          }
        }
      },
      "E422": {
        "description": "Corpo ou parâmetros inválidos (ou invalid_phone).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "validation_error",
                "message": "Corpo ou parâmetros inválidos (ou invalid_phone).",
                "docs_url": "https://avisa.dev/docs/errors#validation_error"
              }
            }
          }
        }
      },
      "E429": {
        "description": "Limite de envio por número atingido. Veja Retry-After.",
        "headers": {
          "Retry-After": {
            "$ref": "#/components/headers/RetryAfter"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "rate_limited",
                "message": "Limite de envio por número atingido. Veja Retry-After.",
                "docs_url": "https://avisa.dev/docs/errors#rate_limited"
              }
            }
          }
        }
      },
      "E500": {
        "description": "Erro interno.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "internal_error",
                "message": "Erro interno.",
                "docs_url": "https://avisa.dev/docs/errors#internal_error"
              }
            }
          }
        }
      },
      "E502": {
        "description": "O WhatsApp recusou ou não respondeu.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "provider_error",
                "message": "O WhatsApp recusou ou não respondeu.",
                "docs_url": "https://avisa.dev/docs/errors#provider_error"
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "docs_url"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "unauthorized",
                  "forbidden",
                  "not_found",
                  "validation_error",
                  "invalid_phone",
                  "number_not_connected",
                  "number_limit",
                  "payment_required",
                  "trial_limit",
                  "rate_limited",
                  "provider_error",
                  "internal_error"
                ]
              },
              "message": {
                "type": "string",
                "description": "Mensagem em português."
              },
              "docs_url": {
                "type": "string",
                "description": "Link para a explicação do erro.",
                "format": "uri"
              }
            }
          }
        }
      },
      "Phone": {
        "type": "string",
        "description": "Telefone só com dígitos e DDI. Aceita também formatado (+55 (31) 99999-9999).",
        "examples": [
          "5531999999999"
        ]
      },
      "Trial": {
        "type": "object",
        "required": [
          "ends_at",
          "messages_used",
          "messages_limit"
        ],
        "properties": {
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "messages_used": {
            "type": "integer",
            "minimum": 0
          },
          "messages_limit": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "Number": {
        "type": "object",
        "required": [
          "id",
          "name",
          "phone",
          "status",
          "plan",
          "billing_status",
          "trial",
          "connected_at",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id com prefixo num_.",
            "pattern": "^num_"
          },
          "name": {
            "type": "string"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "connecting",
              "connected",
              "disconnected"
            ]
          },
          "plan": {
            "type": "string",
            "enum": [
              "trial",
              "monthly",
              "yearly",
              "none"
            ]
          },
          "billing_status": {
            "type": "string",
            "enum": [
              "trialing",
              "active",
              "past_due",
              "canceled"
            ]
          },
          "trial": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Trial"
              },
              {
                "type": "null"
              }
            ]
          },
          "connected_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Qr": {
        "type": "object",
        "required": [
          "base64",
          "code"
        ],
        "properties": {
          "base64": {
            "type": "string",
            "description": "Imagem PNG em data URL.",
            "examples": [
              "data:image/png;base64,iVBORw0..."
            ]
          },
          "code": {
            "type": "string",
            "description": "Conteúdo do QR."
          }
        }
      },
      "NumberWithQr": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Number"
          },
          {
            "type": "object",
            "properties": {
              "qr": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/Qr"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "pairing_code": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        ]
      },
      "QrResponse": {
        "type": "object",
        "required": [
          "status",
          "qr",
          "pairing_code"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "connecting",
              "connected",
              "disconnected"
            ]
          },
          "qr": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Qr"
              },
              {
                "type": "null"
              }
            ]
          },
          "pairing_code": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "CreateNumberRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "examples": [
              "Loja"
            ]
          },
          "pairing_phone": {
            "$ref": "#/components/schemas/Phone",
            "description": "Para conectar por código de pareamento em vez de QR."
          }
        }
      },
      "MessageStatus": {
        "type": "string",
        "enum": [
          "queued",
          "sent",
          "delivered",
          "read",
          "failed",
          "received"
        ]
      },
      "Media": {
        "type": "object",
        "required": [
          "id",
          "url",
          "mime_type",
          "filename",
          "size"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id com prefixo med_.",
            "pattern": "^med_"
          },
          "url": {
            "type": "string",
            "description": "URL assinada, válida por 1 hora.",
            "format": "uri"
          },
          "mime_type": {
            "type": "string"
          },
          "filename": {
            "type": [
              "string",
              "null"
            ]
          },
          "size": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Location": {
        "type": "object",
        "required": [
          "latitude",
          "longitude"
        ],
        "properties": {
          "latitude": {
            "type": "number",
            "minimum": -90,
            "maximum": 90
          },
          "longitude": {
            "type": "number",
            "minimum": -180,
            "maximum": 180
          },
          "name": {
            "type": "string"
          },
          "address": {
            "type": "string"
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "id",
          "number_id",
          "direction",
          "chat",
          "from_phone",
          "type",
          "text",
          "media",
          "location",
          "reply_to",
          "status",
          "error",
          "sent_at",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id com prefixo msg_.",
            "pattern": "^msg_"
          },
          "number_id": {
            "type": "string"
          },
          "direction": {
            "type": "string",
            "enum": [
              "in",
              "out"
            ]
          },
          "chat": {
            "type": "object",
            "required": [
              "type",
              "id",
              "phone",
              "name"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "contact",
                  "group"
                ]
              },
              "id": {
                "type": "string"
              },
              "phone": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "from_phone": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "video",
              "audio",
              "document",
              "location",
              "contact",
              "poll",
              "reaction",
              "sticker",
              "unknown"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "media": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Media"
              },
              {
                "type": "null"
              }
            ]
          },
          "location": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Location"
              },
              {
                "type": "null"
              }
            ]
          },
          "reply_to": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/MessageStatus"
          },
          "error": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string"
                  }
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "sent_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SendMessageCommon": {
        "type": "object",
        "required": [
          "to"
        ],
        "properties": {
          "to": {
            "type": "string",
            "description": "Telefone com DDI ou id de grupo (grp_...).",
            "examples": [
              "5531999999999"
            ]
          },
          "from": {
            "type": "string",
            "description": "Id do número que envia (num_...). Opcional com um número só na conta."
          },
          "reply_to": {
            "type": "string",
            "description": "Id da mensagem respondida (msg_...)."
          },
          "delay_ms": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "description": "Mostra \"digitando...\" antes de enviar."
          }
        }
      },
      "SendMessageRequest": {
        "description": "Um tipo por chamada: envie exatamente um dos campos de conteúdo.",
        "oneOf": [
          {
            "title": "text",
            "description": "Texto.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            ]
          },
          {
            "title": "image",
            "description": "Imagem.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "image"
                ],
                "properties": {
                  "image": {
                    "type": "object",
                    "required": [
                      "url"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "url": {
                        "type": "string",
                        "description": "URL pública (HTTPS) do arquivo.",
                        "format": "uri"
                      },
                      "caption": {
                        "type": "string",
                        "description": "Legenda."
                      }
                    }
                  }
                }
              }
            ]
          },
          {
            "title": "video",
            "description": "Vídeo.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "video"
                ],
                "properties": {
                  "video": {
                    "type": "object",
                    "required": [
                      "url"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "url": {
                        "type": "string",
                        "description": "URL pública (HTTPS) do arquivo.",
                        "format": "uri"
                      },
                      "caption": {
                        "type": "string",
                        "description": "Legenda."
                      }
                    }
                  }
                }
              }
            ]
          },
          {
            "title": "audio",
            "description": "Áudio, entregue como mensagem de voz (PTT).",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "audio"
                ],
                "properties": {
                  "audio": {
                    "type": "object",
                    "required": [
                      "url"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "url": {
                        "type": "string",
                        "description": "URL pública (HTTPS) do arquivo.",
                        "format": "uri"
                      }
                    }
                  }
                }
              }
            ]
          },
          {
            "title": "document",
            "description": "Documento.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "document"
                ],
                "properties": {
                  "document": {
                    "type": "object",
                    "required": [
                      "url"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "url": {
                        "type": "string",
                        "description": "URL pública (HTTPS) do arquivo.",
                        "format": "uri"
                      },
                      "caption": {
                        "type": "string",
                        "description": "Legenda."
                      },
                      "filename": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            ]
          },
          {
            "title": "location",
            "description": "Localização.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "location"
                ],
                "properties": {
                  "location": {
                    "$ref": "#/components/schemas/Location"
                  }
                }
              }
            ]
          },
          {
            "title": "contact",
            "description": "Cartão de contato.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "contact"
                ],
                "properties": {
                  "contact": {
                    "type": "object",
                    "required": [
                      "name",
                      "phone"
                    ],
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "phone": {
                        "$ref": "#/components/schemas/Phone"
                      }
                    }
                  }
                }
              }
            ]
          },
          {
            "title": "poll",
            "description": "Enquete.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "poll"
                ],
                "properties": {
                  "poll": {
                    "type": "object",
                    "required": [
                      "question",
                      "options"
                    ],
                    "properties": {
                      "question": {
                        "type": "string"
                      },
                      "options": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "minItems": 2
                      },
                      "multiple": {
                        "type": "boolean",
                        "default": false
                      }
                    }
                  }
                }
              }
            ]
          },
          {
            "title": "reaction",
            "description": "Reação a uma mensagem.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SendMessageCommon"
              },
              {
                "type": "object",
                "required": [
                  "reaction"
                ],
                "properties": {
                  "reaction": {
                    "type": "object",
                    "required": [
                      "message_id",
                      "emoji"
                    ],
                    "properties": {
                      "message_id": {
                        "type": "string",
                        "description": "Id da mensagem (msg_...)."
                      },
                      "emoji": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            ]
          }
        ]
      },
      "Contact": {
        "type": "object",
        "required": [
          "id",
          "number_id",
          "phone",
          "name",
          "push_name",
          "photo_url",
          "last_message_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id com prefixo ctc_.",
            "pattern": "^ctc_"
          },
          "number_id": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "push_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "photo_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_message_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "CheckRequest": {
        "type": "object",
        "required": [
          "phones"
        ],
        "properties": {
          "phones": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Phone"
            },
            "minItems": 1,
            "maxItems": 50
          },
          "from": {
            "type": "string"
          }
        }
      },
      "CheckResult": {
        "type": "object",
        "required": [
          "phone",
          "exists",
          "whatsapp_id"
        ],
        "properties": {
          "phone": {
            "type": "string"
          },
          "exists": {
            "type": "boolean"
          },
          "whatsapp_id": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Group": {
        "type": "object",
        "required": [
          "id",
          "number_id",
          "name",
          "participants_count"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id com prefixo grp_.",
            "pattern": "^grp_"
          },
          "number_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "participants_count": {
            "type": "integer",
            "minimum": 0
          },
          "participants": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "phone",
                "admin"
              ],
              "properties": {
                "phone": {
                  "type": "string"
                },
                "admin": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "CreateGroupRequest": {
        "type": "object",
        "required": [
          "name",
          "participants"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "participants": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Phone"
            },
            "minItems": 1
          },
          "from": {
            "type": "string"
          }
        }
      },
      "UpdateParticipantsRequest": {
        "type": "object",
        "minProperties": 1,
        "properties": {
          "add": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Phone"
            }
          },
          "remove": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Phone"
            }
          }
        }
      },
      "WebhookEventType": {
        "type": "string",
        "enum": [
          "message.received",
          "message.sent",
          "message.delivered",
          "message.read",
          "message.failed",
          "number.connected",
          "number.disconnected",
          "number.qr_updated",
          "webhook.test"
        ]
      },
      "Webhook": {
        "type": "object",
        "required": [
          "id",
          "url",
          "events",
          "number_id",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id com prefixo whk_.",
            "pattern": "^whk_"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEventType"
            }
          },
          "number_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookWithSecret": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Webhook"
          },
          {
            "type": "object",
            "required": [
              "secret"
            ],
            "properties": {
              "secret": {
                "type": "string",
                "description": "Segredo da assinatura. Só aparece na criação."
              }
            }
          }
        ]
      },
      "CreateWebhookRequest": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEventType"
            },
            "description": "Padrão: todos."
          },
          "number_id": {
            "type": "string"
          }
        }
      },
      "WebhookTestResult": {
        "type": "object",
        "required": [
          "status_code",
          "duration_ms",
          "body"
        ],
        "properties": {
          "status_code": {
            "type": [
              "integer",
              "null"
            ]
          },
          "duration_ms": {
            "type": "integer"
          },
          "body": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "WebhookDelivery": {
        "type": "object",
        "required": [
          "id",
          "event",
          "status_code",
          "attempts",
          "delivered_at",
          "next_retry_at",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "event": {
            "$ref": "#/components/schemas/WebhookEventType"
          },
          "status_code": {
            "type": [
              "integer",
              "null"
            ]
          },
          "attempts": {
            "type": "integer",
            "minimum": 0
          },
          "delivered_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "next_retry_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "required": [
          "id",
          "type",
          "created_at",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id do evento (evt_...). Igual em retentativas.",
            "pattern": "^evt_"
          },
          "type": {
            "$ref": "#/components/schemas/WebhookEventType"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Message"
              },
              {
                "$ref": "#/components/schemas/Number"
              },
              {
                "type": "object"
              }
            ]
          }
        }
      }
    }
  }
}