{
  "info": {
    "title": "Messajo API",
    "version": "dev",
    "description": "API REST do Messajo para WhatsApp, Instagram e Messenger, sobre as APIs oficiais da Meta. Tem duas camadas: a API unificada (`/v1/*`), igual para os três canais, e as rotas espelho da Meta (`/v1/whatsapp/{connection_id}/*`), que repassam o formato da Graph API. Toda chamada se autentica com uma chave de API no cabeçalho `Authorization: Bearer`. Guias, conceitos e exemplos: https://docs.messajo.com.",
    "contact": {
      "url": "https://docs.messajo.com"
    }
  },
  "servers": [
    {
      "url": "https://api.messajo.com/v1",
      "description": "Messajo Cloud"
    }
  ],
  "tags": [
    {
      "name": "account",
      "description": "Conta: a organização e a chave de API da chamada."
    },
    {
      "name": "destinations",
      "description": "Destinos: para onde o Messajo envia os eventos (webhooks assinados)."
    },
    {
      "name": "deliveries",
      "description": "Entregas: cada tentativa de levar um evento a um destino, com reenvio."
    },
    {
      "name": "events",
      "description": "Eventos: o que aconteceu nas conexões, no mesmo envelope que os destinos recebem (30 dias)."
    },
    {
      "name": "logs",
      "description": "Logs: mensagens e chamadas à API dos últimos 30 dias."
    },
    {
      "name": "connections",
      "description": "Conexões: os números conectados, a saúde, o perfil e o nome de usuário."
    },
    {
      "name": "messages",
      "description": "Mensagens: envio pela API unificada e marcação de lida."
    },
    {
      "name": "templates",
      "description": "Templates: modelos de mensagem do WhatsApp aprovados pela Meta."
    },
    {
      "name": "media",
      "description": "Mídia: arquivos para enviar, baixar e compartilhar por link temporário."
    },
    {
      "name": "connection-links",
      "description": "Links de conexão: páginas públicas para alguém de fora conectar um número."
    },
    {
      "name": "whatsapp-mirror",
      "description": "Espelho da Meta: a Graph API do WhatsApp repassada com o token da conexão."
    },
    {
      "name": "messaging-profile",
      "description": "Perfil de mensagens: ice breakers, menu fixo e boas-vindas do Instagram e do Messenger."
    },
    {
      "name": "comments",
      "description": "Comentários e menções do Instagram: listar, responder, responder no Direct, ocultar e apagar."
    },
    {
      "name": "posts",
      "description": "Posts do Instagram: lista, detalhe e cota de publicação."
    },
    {
      "name": "insights",
      "description": "Insights do Instagram: métricas da conta e de cada post."
    },
    {
      "name": "publications",
      "description": "Publicações do Instagram: foto, vídeo, carrossel, Reels e Stories, na hora ou agendadas."
    },
    {
      "name": "instagram-mirror",
      "description": "Espelho da Meta: a Graph API do Instagram repassada com o token da conta."
    },
    {
      "name": "messenger-mirror",
      "description": "Espelho da Meta: a Graph API do Messenger repassada com o token da Página."
    },
    {
      "name": "history",
      "description": "Histórico: conversas, contatos e mensagens guardados, com filtros e paginação por cursor."
    },
    {
      "name": "campaigns",
      "description": "Campanhas: envio em massa de templates do WhatsApp para uma lista, com agendamento e relatório."
    },
    {
      "name": "calls",
      "description": "Ligações do WhatsApp (Calling API, só sinalização): log, ações, permissão de chamada e configurações do número."
    },
    {
      "name": "groups",
      "description": "Grupos do WhatsApp (Groups API): criar, convidar, moderar participantes e pedidos de entrada."
    },
    {
      "name": "flows",
      "description": "WhatsApp Flows: criar, editar o JSON, publicar, deprecar e pré-visualizar, com o endpoint de data exchange hospedado pelo Messajo."
    },
    {
      "name": "commerce",
      "description": "Comércio no WhatsApp: catálogos, produtos, configurações de carrinho e pedidos com Pix, link de pagamento ou boleto."
    },
    {
      "name": "usage",
      "description": "Uso e custos da Meta"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "mj_…",
        "description": "Chave de API criada no painel (Configurações → Chaves de API), enviada como `Authorization: Bearer mj_…`. A chave carrega permissões e, opcionalmente, a lista de conexões que pode usar."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "description": "Corpo único de erro: todo erro da API tem este formato.",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "meta_code",
              "retryable",
              "request_id",
              "docs_url"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "validation_failed",
                  "missing_api_key",
                  "invalid_api_key",
                  "api_key_expired",
                  "api_key_disabled",
                  "unauthenticated",
                  "billing_required",
                  "org_restricted",
                  "org_suspended",
                  "forbidden",
                  "insufficient_permissions",
                  "connection_not_allowed",
                  "organization_key_required",
                  "two_factor_required",
                  "two_factor_mandatory",
                  "no_active_organization",
                  "last_owner",
                  "slug_taken",
                  "org_limit_reached",
                  "reauth_failed",
                  "account_delete_blocked",
                  "not_found",
                  "conflict",
                  "rate_limited",
                  "internal_error",
                  "service_unavailable",
                  "missing_signature",
                  "invalid_signature",
                  "invalid_payload",
                  "payload_too_large",
                  "channel_not_configured",
                  "idempotency_key_reused",
                  "idempotency_in_progress",
                  "destination_url_not_allowed",
                  "destination_limit_reached",
                  "destination_paused",
                  "outside_service_window",
                  "recipient_unavailable",
                  "marketing_limit_reached",
                  "pair_rate_limited",
                  "meta_rate_limited",
                  "template_error",
                  "policy_blocked",
                  "connection_needs_reconnect",
                  "meta_payment_required",
                  "recipient_not_allowed",
                  "media_error",
                  "number_not_registered",
                  "username_not_eligible",
                  "meta_invalid_parameter",
                  "meta_unavailable",
                  "meta_unknown_outcome",
                  "meta_error",
                  "connection_not_active",
                  "connection_restricted",
                  "connection_disabled",
                  "connection_disconnected",
                  "connection_pending",
                  "pin_invalid",
                  "pin_attempts_exhausted",
                  "secret_rotation_pending",
                  "notification_type_locked",
                  "connection_rate_limited",
                  "account_flagged",
                  "signup_code_invalid",
                  "signup_scope_mismatch",
                  "signup_session_expired",
                  "signup_incomplete",
                  "system_user_assignment_failed",
                  "connection_already_exists",
                  "waba_owned_by_other_org",
                  "invitation_invalid",
                  "reconnect_mismatch",
                  "coex_not_on_business_app",
                  "link_invalid",
                  "link_expired",
                  "link_used",
                  "link_locked",
                  "link_password_required",
                  "link_password_invalid",
                  "mirror_path_blocked",
                  "media_too_large",
                  "media_type_not_supported",
                  "voice_conversion_failed",
                  "template_not_found",
                  "coex_not_supported",
                  "instagram_account_not_professional",
                  "instagram_scope_missing",
                  "oauth_state_invalid",
                  "messenger_no_pages",
                  "messenger_page_not_granted",
                  "type_not_supported_by_channel",
                  "tag_not_supported_by_channel",
                  "human_agent_window_closed",
                  "human_agent_not_approved",
                  "meta_permission_denied",
                  "private_reply_window_closed",
                  "private_reply_already_sent",
                  "comment_not_found",
                  "comment_not_owned",
                  "publication_not_editable",
                  "publication_media_invalid",
                  "media_url_not_public",
                  "media_url_expired",
                  "publishing_limit_reached",
                  "container_timeout",
                  "insights_not_available",
                  "welcome_flow_in_use",
                  "signed_request_invalid",
                  "data_deletion_not_found",
                  "invalid_cursor",
                  "retention_out_of_range",
                  "campaign_channel_not_supported",
                  "campaign_template_not_approved",
                  "campaign_template_mapping_invalid",
                  "campaign_not_editable",
                  "campaign_invalid_state",
                  "campaign_no_recipients",
                  "campaign_too_many_recipients",
                  "campaign_import_in_progress",
                  "campaign_schedule_invalid",
                  "spend_cap_reached",
                  "meta_spam_rate_limited",
                  "destination_type_disabled",
                  "no_client_connected",
                  "ws_ticket_invalid",
                  "ws_session_limit",
                  "data_request_in_progress",
                  "data_request_limit",
                  "data_export_expired",
                  "calling_not_supported_in_coex",
                  "calling_not_enabled",
                  "call_not_found",
                  "call_invalid_state",
                  "call_sdp_invalid",
                  "call_sdp_mismatch",
                  "call_permission_required",
                  "call_rate_limited",
                  "call_error",
                  "group_not_supported",
                  "group_not_found",
                  "group_not_active",
                  "group_participant_limit",
                  "group_message_type_not_supported",
                  "flow_not_found",
                  "flow_not_editable",
                  "flow_invalid_json",
                  "flow_handler_required",
                  "flow_key_not_uploaded",
                  "flow_error",
                  "catalog_not_found",
                  "catalog_not_linked",
                  "product_not_found",
                  "commerce_permission_missing",
                  "order_not_found",
                  "order_invalid_transition",
                  "order_reference_taken",
                  "order_totals_mismatch",
                  "payment_not_available",
                  "otp_template_invalid",
                  "body_too_large"
                ],
                "description": "Código estável do erro. Cada código tem uma seção em https://docs.messajo.com/errors."
              },
              "message": {
                "type": "string",
                "description": "Mensagem curta em inglês, para log. Não exiba ao usuário final: traduza pelo `code`."
              },
              "meta_code": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Código de erro devolvido pela Meta, quando o erro veio dela; senão `null`."
              },
              "retryable": {
                "type": "boolean",
                "description": "`true` quando repetir a mesma chamada mais tarde pode dar certo."
              },
              "request_id": {
                "type": "string",
                "description": "ID da requisição, o mesmo do cabeçalho `X-Request-Id`."
              },
              "docs_url": {
                "type": "string",
                "format": "uri",
                "description": "Link para a explicação do código nas docs."
              },
              "retry_after_ms": {
                "type": "integer",
                "description": "Só em `rate_limited`: quanto esperar, em milissegundos, antes de repetir."
              },
              "details": {
                "type": "array",
                "description": "Só em `validation_failed` (um item por campo inválido) e `destination_url_not_allowed` (o motivo em `message`).",
                "items": {
                  "type": "object",
                  "required": [
                    "path",
                    "message"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "Caminho do campo inválido, ex.: `to` ou `items[0].id`."
                    },
                    "message": {
                      "type": "string",
                      "description": "O que está errado no campo."
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "headers": {
      "X-Request-Id": {
        "description": "ID único da requisição. Informe-o ao suporte para localizar a chamada nos logs.",
        "schema": {
          "type": "string"
        }
      },
      "X-RateLimit-Limit": {
        "description": "Requisições permitidas por minuto para esta chave.",
        "schema": {
          "type": "integer"
        }
      },
      "X-RateLimit-Remaining": {
        "description": "Requisições que ainda restam na janela atual.",
        "schema": {
          "type": "integer"
        }
      },
      "X-RateLimit-Reset": {
        "description": "Quando a janela atual reinicia (Unix epoch, em segundos).",
        "schema": {
          "type": "integer"
        }
      },
      "Retry-After": {
        "description": "Segundos a esperar antes de repetir a chamada.",
        "schema": {
          "type": "integer"
        }
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Chave única (8–255 caracteres `A-Z a-z 0-9 . _ : -`) para repetir um `POST` sem efeito duplicado. Vale 24 h por organização, método e caminho: a mesma chave com o mesmo corpo devolve a resposta guardada (cabeçalho `Idempotent-Replayed: true`); com outro corpo, `422 idempotency_key_reused`; enquanto a primeira roda, `409 idempotency_in_progress`.",
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{8,255}$"
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Entrada inválida (`validation_failed`): veja `details`.",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Chave ausente, inválida, expirada ou desativada (`missing_api_key`, `invalid_api_key`, `api_key_expired`, `api_key_disabled`).",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "A chave não tem a permissão exigida ou não pode usar esta conexão (`insufficient_permissions`, `connection_not_allowed`).",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "O recurso não existe ou não pertence à organização (`not_found`).",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Limite de requisições da chave atingido (`rate_limited`): espere `Retry-After` segundos.",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          },
          "Retry-After": {
            "$ref": "#/components/headers/Retry-After"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Conflict": {
        "description": "Conflito com o estado atual (`idempotency_in_progress`, `destination_limit_reached`, `destination_paused`).",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unprocessable": {
        "description": "A `Idempotency-Key` já foi usada com outro corpo (`idempotency_key_reused`).",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "InternalError": {
        "description": "Erro inesperado no servidor (`internal_error`). Pode repetir; se persistir, informe o `request_id`.",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  },
  "openapi": "3.1.1",
  "paths": {
    "/me": {
      "get": {
        "operationId": "getMe",
        "summary": "Consultar a chave atual",
        "description": "Devolve a organização dona da chave e os dados da própria chave (permissões, conexões permitidas, validade). Útil para testar a chave e descobrir o que ela pode fazer. Permissão: qualquer chave válida.",
        "tags": [
          "account"
        ],
        "responses": {
          "200": {
            "description": "A organização e a chave usadas na chamada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "organization": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "ID da organização.",
                          "examples": [
                            "Kq3vT9xZ2mWb7LpR4nYc8sDf1gHj6aEu"
                          ]
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome da organização.",
                          "examples": [
                            "Acme"
                          ]
                        },
                        "slug": {
                          "type": "string",
                          "description": "Identificador curto da organização, usado em URLs.",
                          "examples": [
                            "acme"
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "slug"
                      ],
                      "description": "Organização dona da chave."
                    },
                    "api_key": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "ID da chave.",
                          "examples": [
                            "Zt5rB8wQ1nXc4LmV7pYd2sGf9hJk3aRe"
                          ]
                        },
                        "name": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Nome dado à chave no painel.",
                          "examples": [
                            "production"
                          ]
                        },
                        "start": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Começo da chave, para reconhecê-la sem expor o segredo.",
                          "examples": [
                            "mj_A1b2c3d"
                          ]
                        },
                        "permissions": {
                          "type": "array",
                          "items": {
                            "enum": [
                              "send",
                              "read",
                              "templates",
                              "commerce",
                              "admin"
                            ],
                            "type": "string"
                          },
                          "description": "Permissões da chave: `send`, `read`, `templates` ou `admin` (inclui as demais).",
                          "examples": [
                            [
                              "read"
                            ]
                          ]
                        },
                        "connection_ids": {
                          "anyOf": [
                            {
                              "type": "array",
                              "items": {
                                "type": "string"
                              }
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Conexões que a chave pode usar; `null` = todas as conexões da organização.",
                          "examples": [
                            null
                          ]
                        },
                        "kind": {
                          "enum": [
                            "org",
                            "connection"
                          ],
                          "type": "string",
                          "description": "Tipo da chave: `org` (toda a organização) ou `connection` (presa a uma conexão).",
                          "examples": [
                            "org"
                          ]
                        },
                        "connection_id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Conexão à qual a chave está presa; `null` em chaves de organização.",
                          "examples": [
                            null
                          ]
                        },
                        "connection": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "channel": {
                                  "type": "string"
                                },
                                "label": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                }
                              },
                              "required": [
                                "id",
                                "channel",
                                "label"
                              ]
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Conexão à qual a chave está presa (`id`, `channel`, `label`); `null` em chaves de organização.",
                          "examples": [
                            null
                          ]
                        },
                        "expires_at": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Data de expiração (ISO 8601, UTC); `null` = não expira.",
                          "examples": [
                            "2027-01-01T00:00:00.000Z"
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "start",
                        "permissions",
                        "connection_ids",
                        "kind",
                        "connection_id",
                        "connection",
                        "expires_at"
                      ],
                      "description": "A chave usada na chamada."
                    },
                    "request_id": {
                      "type": "string",
                      "description": "ID desta requisição, o mesmo do cabeçalho `X-Request-Id`.",
                      "examples": [
                        "req_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    }
                  },
                  "required": [
                    "organization",
                    "api_key",
                    "request_id"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/destinations": {
      "get": {
        "operationId": "listDestinations",
        "summary": "Listar destinos",
        "description": "Lista os destinos de eventos da organização. Chave presa a conexões vê só os destinos restritos a elas. Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "responses": {
          "200": {
            "description": "Os destinos da organização.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do destino.",
                            "examples": [
                              "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "type": {
                            "enum": [
                              "webhook",
                              "rabbitmq",
                              "sqs",
                              "kafka",
                              "websocket"
                            ],
                            "type": "string",
                            "description": "Tipo do destino: `webhook` (padrão), `rabbitmq`, `sqs`, `kafka` ou `websocket`. Tipo desligado no servidor → `422 destination_type_disabled`. Não muda depois de criado."
                          },
                          "label": {
                            "type": "string",
                            "description": "Nome do destino, para você reconhecê-lo.",
                            "examples": [
                              "CRM"
                            ]
                          },
                          "url": {
                            "type": "string",
                            "description": "URL `https` que recebe os eventos por `POST`.",
                            "examples": [
                              "https://example.com/webhooks/messajo"
                            ]
                          },
                          "headers": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "name": {
                                  "type": "string",
                                  "description": "Nome do cabeçalho."
                                },
                                "value_last4": {
                                  "type": "string",
                                  "description": "Últimos 4 caracteres do valor do cabeçalho."
                                }
                              },
                              "required": [
                                "name",
                                "value_last4"
                              ]
                            },
                            "description": "Cabeçalhos próprios enviados em toda entrega (até 20). Não podem sobrescrever os `Messajo-*`."
                          },
                          "format": {
                            "enum": [
                              "normalized",
                              "meta"
                            ],
                            "type": "string",
                            "description": "Formato do `data`: `normalized` (igual nos três canais) ou `meta` (o item original da Meta, quando existe)."
                          },
                          "event_types": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Padrões de tipo de evento: tipo exato (`message.received`), família (`message.*`) ou `*`.",
                            "examples": [
                              [
                                "message.*"
                              ]
                            ]
                          },
                          "connection_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conexão dona do destino (`con_…`); `null` = destino global da organização, que recebe eventos de todas as conexões. Não muda depois de criado."
                          },
                          "connection_ids": {
                            "anyOf": [
                              {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Obsoleto: use `connection_id`. Aceita `null` ou uma única conexão; mais de uma → `400 validation_failed`. Na resposta vem derivado de `connection_id` (`[id]` ou `null`)."
                          },
                          "status": {
                            "enum": [
                              "active",
                              "paused",
                              "auto_paused"
                            ],
                            "type": "string",
                            "description": "`active`, `paused` (manual) ou `auto_paused` (falhas seguidas por 24 h)."
                          },
                          "paused_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo da pausa (`manual` ou `failing`); `null` com o destino ativo."
                          },
                          "secret_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres do segredo de assinatura atual."
                          },
                          "previous_secret_expires_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Até quando o segredo anterior também assina (ISO 8601, UTC); `null` = sem segredo anterior.",
                            "examples": [
                              null
                            ]
                          },
                          "failing_since": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Desde quando as entregas falham sem parar (ISO 8601, UTC); `null` = sem falha em curso.",
                            "examples": [
                              null
                            ]
                          },
                          "last_success_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última entrega com sucesso (ISO 8601, UTC); atualizado no máximo a cada 30 s.",
                            "examples": [
                              null
                            ]
                          },
                          "last_failure_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última entrega com falha (ISO 8601, UTC).",
                            "examples": [
                              null
                            ]
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Data de criação (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Data da última alteração (ISO 8601, UTC)."
                          },
                          "config": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {},
                            "description": "Bloco do tipo, sem segredo (senhas viram `password_last4`). `{}` no webhook e com o tipo desligado."
                          },
                          "connected_clients": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Clientes WebSocket conectados agora; `null` fora do tipo `websocket`."
                          }
                        },
                        "required": [
                          "id",
                          "type",
                          "label",
                          "url",
                          "headers",
                          "format",
                          "event_types",
                          "connection_id",
                          "connection_ids",
                          "status",
                          "paused_reason",
                          "secret_last4",
                          "previous_secret_expires_at",
                          "failing_since",
                          "last_success_at",
                          "last_failure_at",
                          "created_at",
                          "updated_at",
                          "config",
                          "connected_clients"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createDestination",
        "summary": "Criar destino",
        "description": "Cria um destino webhook. A URL precisa ser `https` pública (endereços internos são recusados com `destination_url_not_allowed`). O segredo de assinatura vem só nesta resposta: guarde-o. Máximo de 20 destinos por organização. Com chave de conexão, `connection_id` assume a conexão da chave; `connection_id: null` (global) exige chave da organização (`organization_key_required`). Permissão: `admin`. Outros tipos (`rabbitmq`, `sqs`, `kafka`, `websocket`) vão no campo com o nome do tipo, quando ligados no servidor; senão `422 destination_type_disabled`.",
        "tags": [
          "destinations"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Nome do destino, para você reconhecê-lo."
                  },
                  "url": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2048,
                    "description": "URL `https` que recebe os eventos por `POST`."
                  },
                  "headers": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Nome do cabeçalho."
                        },
                        "value": {
                          "type": "string",
                          "maxLength": 4096,
                          "description": "Valor do cabeçalho. Fica cifrado e nunca volta inteiro."
                        }
                      },
                      "required": [
                        "name",
                        "value"
                      ]
                    },
                    "description": "Cabeçalhos próprios enviados em toda entrega (até 20). Não podem sobrescrever os `Messajo-*`."
                  },
                  "format": {
                    "enum": [
                      "normalized",
                      "meta"
                    ],
                    "type": "string",
                    "description": "Formato do `data`: `normalized` (igual nos três canais) ou `meta` (o item original da Meta, quando existe)."
                  },
                  "event_types": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Padrões de tipo de evento: tipo exato (`message.received`), família (`message.*`) ou `*`."
                  },
                  "connection_ids": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Obsoleto: use `connection_id`. Aceita `null` ou uma única conexão; mais de uma → `400 validation_failed`. Na resposta vem derivado de `connection_id` (`[id]` ou `null`)."
                  },
                  "type": {
                    "enum": [
                      "webhook",
                      "rabbitmq",
                      "sqs",
                      "kafka",
                      "websocket"
                    ],
                    "type": "string",
                    "default": "webhook",
                    "description": "Tipo do destino: `webhook` (padrão), `rabbitmq`, `sqs`, `kafka` ou `websocket`. Tipo desligado no servidor → `422 destination_type_disabled`. Não muda depois de criado."
                  },
                  "connection_id": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Conexão dona do destino (`con_…`); `null` = destino global da organização, que recebe eventos de todas as conexões. Não muda depois de criado."
                  },
                  "rabbitmq": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "minLength": 1
                      },
                      "exchange": {
                        "type": "string",
                        "maxLength": 255
                      },
                      "routing_key": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "default": "messajo.{type}"
                      },
                      "persistent": {
                        "type": "boolean",
                        "default": true
                      }
                    },
                    "required": [
                      "url",
                      "exchange"
                    ],
                    "description": "Só com `type: rabbitmq`: `url` (`amqps://usuário:senha@host:5671/vhost`), `exchange`, `routing_key` (padrão `messajo.{type}`) e `persistent` (padrão `true`)."
                  },
                  "sqs": {
                    "type": "object",
                    "properties": {
                      "queue_url": {
                        "type": "string",
                        "minLength": 1
                      },
                      "region": {
                        "type": "string",
                        "pattern": "^[a-z]{2}(-[a-z]+)+-\\d+$"
                      },
                      "access_key_id": {
                        "type": "string",
                        "minLength": 1
                      },
                      "secret_access_key": {
                        "type": "string",
                        "minLength": 1
                      },
                      "session_token": {
                        "type": "string",
                        "minLength": 1
                      },
                      "message_group_id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "default": "{connection}"
                      }
                    },
                    "required": [
                      "queue_url",
                      "region",
                      "access_key_id",
                      "secret_access_key"
                    ],
                    "description": "Só com `type: sqs`: `queue_url`, `region`, `access_key_id`, `secret_access_key`, `session_token` opcional e `message_group_id` (filas `.fifo`, padrão `{connection}`)."
                  },
                  "kafka": {
                    "type": "object",
                    "properties": {
                      "brokers": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 10,
                        "items": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "topic": {
                        "type": "string",
                        "pattern": "^[a-zA-Z0-9._-]{1,249}$"
                      },
                      "ssl": {
                        "type": "boolean",
                        "default": true
                      },
                      "sasl": {
                        "anyOf": [
                          {
                            "type": "object",
                            "properties": {
                              "mechanism": {
                                "enum": [
                                  "plain",
                                  "scram-sha-256",
                                  "scram-sha-512"
                                ],
                                "type": "string"
                              },
                              "username": {
                                "type": "string",
                                "minLength": 1
                              },
                              "password": {
                                "type": "string",
                                "minLength": 1
                              }
                            },
                            "required": [
                              "mechanism",
                              "username",
                              "password"
                            ]
                          },
                          {
                            "type": "null"
                          }
                        ],
                        "default": null
                      },
                      "key": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "default": "{connection}"
                      },
                      "client_id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "default": "messajo"
                      }
                    },
                    "required": [
                      "brokers",
                      "topic"
                    ],
                    "description": "Só com `type: kafka`: `brokers` (até 10), `topic`, `ssl` (padrão `true`), `sasl` (`plain`, `scram-sha-256` ou `scram-sha-512`), `key` (padrão `{connection}`) e `client_id`."
                  },
                  "websocket": {
                    "type": "object",
                    "additionalProperties": false,
                    "description": "Só com `type: websocket`: objeto vazio. Os eventos chegam em `GET /v1/ws` e o cliente confirma cada um com `ack`."
                  }
                },
                "required": [
                  "label",
                  "format",
                  "event_types"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O destino criado, com o segredo de assinatura.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo do destino: `webhook` (padrão), `rabbitmq`, `sqs`, `kafka` ou `websocket`. Tipo desligado no servidor → `422 destination_type_disabled`. Não muda depois de criado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do destino, para você reconhecê-lo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recebe os eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nome do cabeçalho."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres do valor do cabeçalho."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeçalhos próprios enviados em toda entrega (até 20). Não podem sobrescrever os `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato do `data`: `normalized` (igual nos três canais) ou `meta` (o item original da Meta, quando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Padrões de tipo de evento: tipo exato (`message.received`), família (`message.*`) ou `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão dona do destino (`con_…`); `null` = destino global da organização, que recebe eventos de todas as conexões. Não muda depois de criado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: use `connection_id`. Aceita `null` ou uma única conexão; mais de uma → `400 validation_failed`. Na resposta vem derivado de `connection_id` (`[id]` ou `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) ou `auto_paused` (falhas seguidas por 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa (`manual` ou `failing`); `null` com o destino ativo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do segredo de assinatura atual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Até quando o segredo anterior também assina (ISO 8601, UTC); `null` = sem segredo anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde quando as entregas falham sem parar (ISO 8601, UTC); `null` = sem falha em curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com sucesso (ISO 8601, UTC); atualizado no máximo a cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com falha (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Data da última alteração (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloco do tipo, sem segredo (senhas viram `password_last4`). `{}` no webhook e com o tipo desligado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados agora; `null` fora do tipo `websocket`."
                    },
                    "secret": {
                      "type": "string",
                      "description": "Segredo de assinatura (`whsec_…`). Só aparece nesta resposta: guarde-o para verificar o `Messajo-Signature`."
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "label",
                    "url",
                    "headers",
                    "format",
                    "event_types",
                    "connection_id",
                    "connection_ids",
                    "status",
                    "paused_reason",
                    "secret_last4",
                    "previous_secret_expires_at",
                    "failing_since",
                    "last_success_at",
                    "last_failure_at",
                    "created_at",
                    "updated_at",
                    "config",
                    "connected_clients",
                    "secret"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/destinations/{id}": {
      "get": {
        "operationId": "getDestination",
        "summary": "Consultar destino",
        "description": "Devolve um destino. Os valores dos cabeçalhos próprios saem mascarados. Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O destino.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo do destino: `webhook` (padrão), `rabbitmq`, `sqs`, `kafka` ou `websocket`. Tipo desligado no servidor → `422 destination_type_disabled`. Não muda depois de criado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do destino, para você reconhecê-lo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recebe os eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nome do cabeçalho."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres do valor do cabeçalho."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeçalhos próprios enviados em toda entrega (até 20). Não podem sobrescrever os `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato do `data`: `normalized` (igual nos três canais) ou `meta` (o item original da Meta, quando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Padrões de tipo de evento: tipo exato (`message.received`), família (`message.*`) ou `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão dona do destino (`con_…`); `null` = destino global da organização, que recebe eventos de todas as conexões. Não muda depois de criado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: use `connection_id`. Aceita `null` ou uma única conexão; mais de uma → `400 validation_failed`. Na resposta vem derivado de `connection_id` (`[id]` ou `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) ou `auto_paused` (falhas seguidas por 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa (`manual` ou `failing`); `null` com o destino ativo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do segredo de assinatura atual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Até quando o segredo anterior também assina (ISO 8601, UTC); `null` = sem segredo anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde quando as entregas falham sem parar (ISO 8601, UTC); `null` = sem falha em curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com sucesso (ISO 8601, UTC); atualizado no máximo a cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com falha (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Data da última alteração (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloco do tipo, sem segredo (senhas viram `password_last4`). `{}` no webhook e com o tipo desligado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados agora; `null` fora do tipo `websocket`."
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "label",
                    "url",
                    "headers",
                    "format",
                    "event_types",
                    "connection_id",
                    "connection_ids",
                    "status",
                    "paused_reason",
                    "secret_last4",
                    "previous_secret_expires_at",
                    "failing_since",
                    "last_success_at",
                    "last_failure_at",
                    "created_at",
                    "updated_at",
                    "config",
                    "connected_clients"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateDestination",
        "summary": "Alterar destino",
        "description": "Altera os campos enviados; os ausentes ficam como estão. O segredo não muda aqui: use `rotate-secret`. Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Nome do destino, para você reconhecê-lo."
                  },
                  "url": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2048,
                    "description": "URL `https` que recebe os eventos por `POST`."
                  },
                  "headers": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Nome do cabeçalho."
                        },
                        "value": {
                          "type": "string",
                          "maxLength": 4096,
                          "description": "Valor do cabeçalho. Fica cifrado e nunca volta inteiro."
                        }
                      },
                      "required": [
                        "name",
                        "value"
                      ]
                    },
                    "description": "Cabeçalhos próprios enviados em toda entrega (até 20). Não podem sobrescrever os `Messajo-*`."
                  },
                  "format": {
                    "enum": [
                      "normalized",
                      "meta"
                    ],
                    "type": "string",
                    "description": "Formato do `data`: `normalized` (igual nos três canais) ou `meta` (o item original da Meta, quando existe)."
                  },
                  "event_types": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Padrões de tipo de evento: tipo exato (`message.received`), família (`message.*`) ou `*`."
                  },
                  "connection_id": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Conexão dona do destino (`con_…`); `null` = destino global da organização, que recebe eventos de todas as conexões. Não muda depois de criado."
                  },
                  "connection_ids": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Obsoleto: use `connection_id`. Aceita `null` ou uma única conexão; mais de uma → `400 validation_failed`. Na resposta vem derivado de `connection_id` (`[id]` ou `null`)."
                  },
                  "rabbitmq": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "minLength": 1
                      },
                      "exchange": {
                        "type": "string",
                        "maxLength": 255
                      },
                      "routing_key": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "default": "messajo.{type}"
                      },
                      "persistent": {
                        "type": "boolean",
                        "default": true
                      }
                    },
                    "required": [
                      "url",
                      "exchange"
                    ],
                    "description": "Só com `type: rabbitmq`: `url` (`amqps://usuário:senha@host:5671/vhost`), `exchange`, `routing_key` (padrão `messajo.{type}`) e `persistent` (padrão `true`)."
                  },
                  "sqs": {
                    "type": "object",
                    "properties": {
                      "queue_url": {
                        "type": "string",
                        "minLength": 1
                      },
                      "region": {
                        "type": "string",
                        "pattern": "^[a-z]{2}(-[a-z]+)+-\\d+$"
                      },
                      "access_key_id": {
                        "type": "string",
                        "minLength": 1
                      },
                      "secret_access_key": {
                        "type": "string",
                        "minLength": 1
                      },
                      "session_token": {
                        "type": "string",
                        "minLength": 1
                      },
                      "message_group_id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "default": "{connection}"
                      }
                    },
                    "required": [
                      "queue_url",
                      "region",
                      "access_key_id",
                      "secret_access_key"
                    ],
                    "description": "Só com `type: sqs`: `queue_url`, `region`, `access_key_id`, `secret_access_key`, `session_token` opcional e `message_group_id` (filas `.fifo`, padrão `{connection}`)."
                  },
                  "kafka": {
                    "type": "object",
                    "properties": {
                      "brokers": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 10,
                        "items": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "topic": {
                        "type": "string",
                        "pattern": "^[a-zA-Z0-9._-]{1,249}$"
                      },
                      "ssl": {
                        "type": "boolean",
                        "default": true
                      },
                      "sasl": {
                        "anyOf": [
                          {
                            "type": "object",
                            "properties": {
                              "mechanism": {
                                "enum": [
                                  "plain",
                                  "scram-sha-256",
                                  "scram-sha-512"
                                ],
                                "type": "string"
                              },
                              "username": {
                                "type": "string",
                                "minLength": 1
                              },
                              "password": {
                                "type": "string",
                                "minLength": 1
                              }
                            },
                            "required": [
                              "mechanism",
                              "username",
                              "password"
                            ]
                          },
                          {
                            "type": "null"
                          }
                        ],
                        "default": null
                      },
                      "key": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "default": "{connection}"
                      },
                      "client_id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255,
                        "default": "messajo"
                      }
                    },
                    "required": [
                      "brokers",
                      "topic"
                    ],
                    "description": "Só com `type: kafka`: `brokers` (até 10), `topic`, `ssl` (padrão `true`), `sasl` (`plain`, `scram-sha-256` ou `scram-sha-512`), `key` (padrão `{connection}`) e `client_id`."
                  },
                  "websocket": {
                    "type": "object",
                    "additionalProperties": false,
                    "description": "Só com `type: websocket`: objeto vazio. Os eventos chegam em `GET /v1/ws` e o cliente confirma cada um com `ack`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O destino alterado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo do destino: `webhook` (padrão), `rabbitmq`, `sqs`, `kafka` ou `websocket`. Tipo desligado no servidor → `422 destination_type_disabled`. Não muda depois de criado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do destino, para você reconhecê-lo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recebe os eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nome do cabeçalho."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres do valor do cabeçalho."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeçalhos próprios enviados em toda entrega (até 20). Não podem sobrescrever os `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato do `data`: `normalized` (igual nos três canais) ou `meta` (o item original da Meta, quando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Padrões de tipo de evento: tipo exato (`message.received`), família (`message.*`) ou `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão dona do destino (`con_…`); `null` = destino global da organização, que recebe eventos de todas as conexões. Não muda depois de criado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: use `connection_id`. Aceita `null` ou uma única conexão; mais de uma → `400 validation_failed`. Na resposta vem derivado de `connection_id` (`[id]` ou `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) ou `auto_paused` (falhas seguidas por 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa (`manual` ou `failing`); `null` com o destino ativo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do segredo de assinatura atual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Até quando o segredo anterior também assina (ISO 8601, UTC); `null` = sem segredo anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde quando as entregas falham sem parar (ISO 8601, UTC); `null` = sem falha em curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com sucesso (ISO 8601, UTC); atualizado no máximo a cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com falha (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Data da última alteração (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloco do tipo, sem segredo (senhas viram `password_last4`). `{}` no webhook e com o tipo desligado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados agora; `null` fora do tipo `websocket`."
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "label",
                    "url",
                    "headers",
                    "format",
                    "event_types",
                    "connection_id",
                    "connection_ids",
                    "status",
                    "paused_reason",
                    "secret_last4",
                    "previous_secret_expires_at",
                    "failing_since",
                    "last_success_at",
                    "last_failure_at",
                    "created_at",
                    "updated_at",
                    "config",
                    "connected_clients"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteDestination",
        "summary": "Excluir destino",
        "description": "Exclui o destino e o histórico de entregas dele. Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmação da exclusão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do destino."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/destinations/{id}/rotate-secret": {
      "post": {
        "operationId": "rotateDestinationSecret",
        "summary": "Trocar segredo",
        "description": "Gera um segredo de assinatura novo. O anterior continua assinando junto por `keep_previous_hours` (0 a 72, padrão 24), para você trocar sem perder entregas. Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "keep_previous_hours": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 72,
                    "default": 24,
                    "description": "Por quantas horas o segredo anterior continua assinando (0 a 72)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O segredo novo e até quando o anterior vale.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "secret": {
                      "type": "string",
                      "description": "Segredo de assinatura (`whsec_…`). Só aparece nesta resposta: guarde-o para verificar o `Messajo-Signature`."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Até quando o segredo anterior também assina (ISO 8601, UTC); `null` = sem segredo anterior.",
                      "examples": [
                        null
                      ]
                    }
                  },
                  "required": [
                    "secret",
                    "previous_secret_expires_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/destinations/{id}/pause": {
      "post": {
        "operationId": "pauseDestination",
        "summary": "Pausar destino",
        "description": "Para de entregar ao destino. Eventos novos geram entregas com falha `destination_paused`, que podem ser reenviadas depois. Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O destino pausado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo do destino: `webhook` (padrão), `rabbitmq`, `sqs`, `kafka` ou `websocket`. Tipo desligado no servidor → `422 destination_type_disabled`. Não muda depois de criado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do destino, para você reconhecê-lo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recebe os eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nome do cabeçalho."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres do valor do cabeçalho."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeçalhos próprios enviados em toda entrega (até 20). Não podem sobrescrever os `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato do `data`: `normalized` (igual nos três canais) ou `meta` (o item original da Meta, quando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Padrões de tipo de evento: tipo exato (`message.received`), família (`message.*`) ou `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão dona do destino (`con_…`); `null` = destino global da organização, que recebe eventos de todas as conexões. Não muda depois de criado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: use `connection_id`. Aceita `null` ou uma única conexão; mais de uma → `400 validation_failed`. Na resposta vem derivado de `connection_id` (`[id]` ou `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) ou `auto_paused` (falhas seguidas por 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa (`manual` ou `failing`); `null` com o destino ativo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do segredo de assinatura atual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Até quando o segredo anterior também assina (ISO 8601, UTC); `null` = sem segredo anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde quando as entregas falham sem parar (ISO 8601, UTC); `null` = sem falha em curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com sucesso (ISO 8601, UTC); atualizado no máximo a cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com falha (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Data da última alteração (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloco do tipo, sem segredo (senhas viram `password_last4`). `{}` no webhook e com o tipo desligado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados agora; `null` fora do tipo `websocket`."
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "label",
                    "url",
                    "headers",
                    "format",
                    "event_types",
                    "connection_id",
                    "connection_ids",
                    "status",
                    "paused_reason",
                    "secret_last4",
                    "previous_secret_expires_at",
                    "failing_since",
                    "last_success_at",
                    "last_failure_at",
                    "created_at",
                    "updated_at",
                    "config",
                    "connected_clients"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/destinations/{id}/resume": {
      "post": {
        "operationId": "resumeDestination",
        "summary": "Retomar destino",
        "description": "Volta a entregar ao destino (também depois de uma pausa automática). Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O destino ativo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo do destino: `webhook` (padrão), `rabbitmq`, `sqs`, `kafka` ou `websocket`. Tipo desligado no servidor → `422 destination_type_disabled`. Não muda depois de criado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do destino, para você reconhecê-lo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recebe os eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nome do cabeçalho."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres do valor do cabeçalho."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeçalhos próprios enviados em toda entrega (até 20). Não podem sobrescrever os `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato do `data`: `normalized` (igual nos três canais) ou `meta` (o item original da Meta, quando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Padrões de tipo de evento: tipo exato (`message.received`), família (`message.*`) ou `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão dona do destino (`con_…`); `null` = destino global da organização, que recebe eventos de todas as conexões. Não muda depois de criado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: use `connection_id`. Aceita `null` ou uma única conexão; mais de uma → `400 validation_failed`. Na resposta vem derivado de `connection_id` (`[id]` ou `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) ou `auto_paused` (falhas seguidas por 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa (`manual` ou `failing`); `null` com o destino ativo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do segredo de assinatura atual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Até quando o segredo anterior também assina (ISO 8601, UTC); `null` = sem segredo anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde quando as entregas falham sem parar (ISO 8601, UTC); `null` = sem falha em curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com sucesso (ISO 8601, UTC); atualizado no máximo a cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega com falha (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Data da última alteração (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloco do tipo, sem segredo (senhas viram `password_last4`). `{}` no webhook e com o tipo desligado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados agora; `null` fora do tipo `websocket`."
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "label",
                    "url",
                    "headers",
                    "format",
                    "event_types",
                    "connection_id",
                    "connection_ids",
                    "status",
                    "paused_reason",
                    "secret_last4",
                    "previous_secret_expires_at",
                    "failing_since",
                    "last_success_at",
                    "last_failure_at",
                    "created_at",
                    "updated_at",
                    "config",
                    "connected_clients"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/destinations/{id}/test": {
      "post": {
        "operationId": "testDestination",
        "summary": "Testar destino",
        "description": "Envia agora um evento `destination.test` ao destino e espera a resposta (até 10 s, sem repetição). Funciona com o destino pausado. Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A entrega do teste, com o resultado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da entrega.",
                      "examples": [
                        "dlv_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "destination_id": {
                      "type": "string",
                      "description": "Destino da entrega."
                    },
                    "event_id": {
                      "type": "string",
                      "description": "Evento entregue."
                    },
                    "event_type": {
                      "type": "string",
                      "description": "Tipo do evento.",
                      "examples": [
                        "message.received"
                      ]
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "retrying",
                        "succeeded",
                        "failed",
                        "canceled",
                        "held"
                      ],
                      "type": "string",
                      "description": "`pending`, `retrying` (vai tentar de novo), `succeeded`, `failed` ou `held` (organização suspensa)."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Tentativas feitas até agora."
                    },
                    "next_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Próxima tentativa (ISO 8601, UTC); `null` se não haverá outra."
                    },
                    "last_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última tentativa (ISO 8601, UTC)."
                    },
                    "last_status_code": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status HTTP da última resposta do destino; `null` sem resposta (rede, timeout)."
                    },
                    "last_error": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da última falha."
                    },
                    "last_duration_ms": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração da última tentativa, em milissegundos."
                    },
                    "redelivery_of": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Entrega original, quando esta é um reenvio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "succeeded_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a entrega teve sucesso (ISO 8601, UTC)."
                    },
                    "failed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a entrega falhou de vez (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "destination_id",
                    "event_id",
                    "event_type",
                    "status",
                    "attempts",
                    "next_attempt_at",
                    "last_attempt_at",
                    "last_status_code",
                    "last_error",
                    "last_duration_ms",
                    "redelivery_of",
                    "created_at",
                    "succeeded_at",
                    "failed_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/destinations/{id}/redeliver-failed": {
      "post": {
        "operationId": "redeliverFailedDeliveries",
        "summary": "Reenviar falhas",
        "description": "Reenvia as entregas com falha do destino no intervalo, até 1000 por chamada (`has_more` diz se sobrou). O destino precisa estar ativo. Permissão: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "since": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Início do intervalo (ISO 8601)."
                  },
                  "until": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Fim do intervalo (ISO 8601); ausente = agora."
                  }
                },
                "required": [
                  "since"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Quantas entregas foram reenfileiradas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "queued": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Entregas reenfileiradas nesta chamada."
                    },
                    "has_more": {
                      "type": "boolean",
                      "description": "`true` se ainda há falhas no intervalo: chame de novo."
                    }
                  },
                  "required": [
                    "queued",
                    "has_more"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/destinations/{id}/ws-tickets": {
      "post": {
        "operationId": "createWebSocketTicket",
        "summary": "Criar ticket do WebSocket",
        "description": "Gera um ticket de uso único, válido por 60 s, para abrir `GET /v1/ws?ticket=…` num destino `websocket` ativo (navegador sem cabeçalho `Authorization`). Permissão: `read`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "O ticket e a URL de conexão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ticket": {
                      "type": "string",
                      "description": "Ticket de uso único (`wst_…`), válido por 60 s."
                    },
                    "url": {
                      "type": "string",
                      "description": "URL pronta para abrir o WebSocket com o ticket."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Quando o ticket vence (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "ticket",
                    "url",
                    "expires_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/deliveries": {
      "get": {
        "operationId": "listDeliveries",
        "summary": "Listar entregas",
        "description": "Lista as entregas de eventos aos destinos (30 dias), da mais nova para a mais antiga. Permissão: `read`.",
        "tags": [
          "deliveries"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "destination_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Destino da entrega."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending",
                "retrying",
                "succeeded",
                "failed",
                "canceled",
                "held"
              ],
              "type": "string",
              "description": "`pending`, `retrying` (vai tentar de novo), `succeeded`, `failed` ou `held` (organização suspensa)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "event_type",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Tipo do evento."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Só entregas criadas a partir desta data (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Só entregas criadas até esta data (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "As entregas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da entrega.",
                            "examples": [
                              "dlv_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "destination_id": {
                            "type": "string",
                            "description": "Destino da entrega."
                          },
                          "event_id": {
                            "type": "string",
                            "description": "Evento entregue."
                          },
                          "event_type": {
                            "type": "string",
                            "description": "Tipo do evento.",
                            "examples": [
                              "message.received"
                            ]
                          },
                          "status": {
                            "enum": [
                              "pending",
                              "retrying",
                              "succeeded",
                              "failed",
                              "canceled",
                              "held"
                            ],
                            "type": "string",
                            "description": "`pending`, `retrying` (vai tentar de novo), `succeeded`, `failed` ou `held` (organização suspensa)."
                          },
                          "attempts": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Tentativas feitas até agora."
                          },
                          "next_attempt_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Próxima tentativa (ISO 8601, UTC); `null` se não haverá outra."
                          },
                          "last_attempt_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última tentativa (ISO 8601, UTC)."
                          },
                          "last_status_code": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Status HTTP da última resposta do destino; `null` sem resposta (rede, timeout)."
                          },
                          "last_error": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo da última falha."
                          },
                          "last_duration_ms": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Duração da última tentativa, em milissegundos."
                          },
                          "redelivery_of": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Entrega original, quando esta é um reenvio."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Data de criação (ISO 8601, UTC)."
                          },
                          "succeeded_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando a entrega teve sucesso (ISO 8601, UTC)."
                          },
                          "failed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando a entrega falhou de vez (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "destination_id",
                          "event_id",
                          "event_type",
                          "status",
                          "attempts",
                          "next_attempt_at",
                          "last_attempt_at",
                          "last_status_code",
                          "last_error",
                          "last_duration_ms",
                          "redelivery_of",
                          "created_at",
                          "succeeded_at",
                          "failed_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/deliveries/{id}": {
      "get": {
        "operationId": "getDelivery",
        "summary": "Consultar entrega",
        "description": "Devolve uma entrega com o registro das últimas 20 tentativas. Permissão: `read`.",
        "tags": [
          "deliveries"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da entrega."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A entrega e as tentativas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da entrega.",
                      "examples": [
                        "dlv_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "destination_id": {
                      "type": "string",
                      "description": "Destino da entrega."
                    },
                    "event_id": {
                      "type": "string",
                      "description": "Evento entregue."
                    },
                    "event_type": {
                      "type": "string",
                      "description": "Tipo do evento.",
                      "examples": [
                        "message.received"
                      ]
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "retrying",
                        "succeeded",
                        "failed",
                        "canceled",
                        "held"
                      ],
                      "type": "string",
                      "description": "`pending`, `retrying` (vai tentar de novo), `succeeded`, `failed` ou `held` (organização suspensa)."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Tentativas feitas até agora."
                    },
                    "next_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Próxima tentativa (ISO 8601, UTC); `null` se não haverá outra."
                    },
                    "last_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última tentativa (ISO 8601, UTC)."
                    },
                    "last_status_code": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status HTTP da última resposta do destino; `null` sem resposta (rede, timeout)."
                    },
                    "last_error": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da última falha."
                    },
                    "last_duration_ms": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração da última tentativa, em milissegundos."
                    },
                    "redelivery_of": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Entrega original, quando esta é um reenvio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "succeeded_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a entrega teve sucesso (ISO 8601, UTC)."
                    },
                    "failed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a entrega falhou de vez (ISO 8601, UTC)."
                    },
                    "attempt_log": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "n": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Número da tentativa (1 = primeira)."
                          },
                          "at": {
                            "type": "string",
                            "description": "Quando a tentativa foi feita (ISO 8601, UTC)."
                          },
                          "status_code": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Status HTTP da resposta; `null` sem resposta."
                          },
                          "duration_ms": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Duração da tentativa, em milissegundos."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo da falha; `null` com sucesso."
                          },
                          "response_excerpt": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Início do corpo da resposta (até 1 KiB)."
                          }
                        },
                        "required": [
                          "n",
                          "at",
                          "status_code",
                          "duration_ms",
                          "error",
                          "response_excerpt"
                        ]
                      },
                      "description": "Últimas 20 tentativas."
                    }
                  },
                  "required": [
                    "id",
                    "destination_id",
                    "event_id",
                    "event_type",
                    "status",
                    "attempts",
                    "next_attempt_at",
                    "last_attempt_at",
                    "last_status_code",
                    "last_error",
                    "last_duration_ms",
                    "redelivery_of",
                    "created_at",
                    "succeeded_at",
                    "failed_at",
                    "attempt_log"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/deliveries/{id}/redeliver": {
      "post": {
        "operationId": "redeliverDelivery",
        "summary": "Reenviar entrega",
        "description": "Cria uma entrega nova do mesmo evento para o mesmo destino. O destino precisa estar ativo. Permissão: `admin`.",
        "tags": [
          "deliveries"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da entrega."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "A entrega nova.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da entrega.",
                      "examples": [
                        "dlv_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "destination_id": {
                      "type": "string",
                      "description": "Destino da entrega."
                    },
                    "event_id": {
                      "type": "string",
                      "description": "Evento entregue."
                    },
                    "event_type": {
                      "type": "string",
                      "description": "Tipo do evento.",
                      "examples": [
                        "message.received"
                      ]
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "retrying",
                        "succeeded",
                        "failed",
                        "canceled",
                        "held"
                      ],
                      "type": "string",
                      "description": "`pending`, `retrying` (vai tentar de novo), `succeeded`, `failed` ou `held` (organização suspensa)."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Tentativas feitas até agora."
                    },
                    "next_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Próxima tentativa (ISO 8601, UTC); `null` se não haverá outra."
                    },
                    "last_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última tentativa (ISO 8601, UTC)."
                    },
                    "last_status_code": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status HTTP da última resposta do destino; `null` sem resposta (rede, timeout)."
                    },
                    "last_error": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da última falha."
                    },
                    "last_duration_ms": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração da última tentativa, em milissegundos."
                    },
                    "redelivery_of": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Entrega original, quando esta é um reenvio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "succeeded_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a entrega teve sucesso (ISO 8601, UTC)."
                    },
                    "failed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a entrega falhou de vez (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "destination_id",
                    "event_id",
                    "event_type",
                    "status",
                    "attempts",
                    "next_attempt_at",
                    "last_attempt_at",
                    "last_status_code",
                    "last_error",
                    "last_duration_ms",
                    "redelivery_of",
                    "created_at",
                    "succeeded_at",
                    "failed_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/events": {
      "get": {
        "operationId": "listEvents",
        "summary": "Listar eventos",
        "description": "Lista os eventos dos últimos 30 dias no mesmo envelope que os destinos recebem. Chave presa a conexões vê só os eventos delas. Permissão: `read`.",
        "tags": [
          "events"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Tipo do evento, ex.: `message.received`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Só eventos desta conexão."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Só eventos gravados a partir desta data (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "enum": [
                "normalized",
                "meta"
              ],
              "type": "string",
              "default": "normalized",
              "description": "Formato de `data`: `normalized` (padrão) ou `meta`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Os eventos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do evento (igual ao cabeçalho `Messajo-Event-Id`).",
                            "examples": [
                              "evt_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "type": {
                            "type": "string",
                            "description": "Tipo do evento, ex.: `message.received`.",
                            "examples": [
                              "message.received"
                            ]
                          },
                          "format": {
                            "enum": [
                              "normalized",
                              "meta"
                            ],
                            "type": "string",
                            "description": "Formato usado em `data`. Evento sem item da Meta (ex.: `message.sent`) sai `normalized` mesmo pedindo `meta`."
                          },
                          "org": {
                            "type": "string",
                            "description": "Organização do evento."
                          },
                          "connection": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conexão do evento; `null` em evento da organização (ex.: `destination.test`)."
                          },
                          "channel": {
                            "anyOf": [
                              {
                                "enum": [
                                  "whatsapp",
                                  "instagram",
                                  "messenger"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Canal da conexão: `whatsapp`, `instagram` ou `messenger`; `null` em evento da organização."
                          },
                          "timestamp": {
                            "type": "string",
                            "description": "Quando o fato aconteceu (ISO 8601, UTC)."
                          },
                          "sequence": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Ordem do evento na conversa (cresce de 1 em 1); `null` em evento fora de conversa."
                          },
                          "data": {
                            "description": "Dados do evento, no formato de `format`."
                          }
                        },
                        "required": [
                          "id",
                          "type",
                          "format",
                          "org",
                          "connection",
                          "channel",
                          "timestamp",
                          "sequence"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/events/{id}": {
      "get": {
        "operationId": "getEvent",
        "summary": "Consultar evento",
        "description": "Devolve um evento no envelope de entrega, no formato pedido. Permissão: `read`.",
        "tags": [
          "events"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do evento (igual ao cabeçalho `Messajo-Event-Id`)."
            }
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "enum": [
                "normalized",
                "meta"
              ],
              "type": "string",
              "default": "normalized",
              "description": "Formato de `data`: `normalized` (padrão) ou `meta`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "O evento.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do evento (igual ao cabeçalho `Messajo-Event-Id`).",
                      "examples": [
                        "evt_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "type": "string",
                      "description": "Tipo do evento, ex.: `message.received`.",
                      "examples": [
                        "message.received"
                      ]
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato usado em `data`. Evento sem item da Meta (ex.: `message.sent`) sai `normalized` mesmo pedindo `meta`."
                    },
                    "org": {
                      "type": "string",
                      "description": "Organização do evento."
                    },
                    "connection": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão do evento; `null` em evento da organização (ex.: `destination.test`)."
                    },
                    "channel": {
                      "anyOf": [
                        {
                          "enum": [
                            "whatsapp",
                            "instagram",
                            "messenger"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Canal da conexão: `whatsapp`, `instagram` ou `messenger`; `null` em evento da organização."
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "Quando o fato aconteceu (ISO 8601, UTC)."
                    },
                    "sequence": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Ordem do evento na conversa (cresce de 1 em 1); `null` em evento fora de conversa."
                    },
                    "data": {
                      "description": "Dados do evento, no formato de `format`."
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "format",
                    "org",
                    "connection",
                    "channel",
                    "timestamp",
                    "sequence"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/logs/messages": {
      "get": {
        "operationId": "listMessageLogs",
        "summary": "Log de mensagens",
        "description": "Lista as mensagens recebidas e enviadas nos últimos 30 dias, sem o conteúdo. `since` mais antigo que 30 dias dá `validation_failed`. Permissão: `read`.",
        "tags": [
          "logs"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Conexão da mensagem."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "enum": [
                "inbound",
                "outbound"
              ],
              "type": "string",
              "description": "`inbound` (recebida) ou `outbound` (enviada)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "received",
                "queued",
                "sent",
                "delivered",
                "read",
                "played",
                "failed",
                "deleted"
              ],
              "type": "string",
              "description": "Status atual da mensagem."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Tipo do conteúdo, ex.: `text`, `image`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Início do intervalo (ISO 8601), no máximo 30 dias atrás; padrão = 30 dias atrás."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fim do intervalo (ISO 8601); padrão = agora."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "As mensagens.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da mensagem."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando a mensagem foi gravada (ISO 8601, UTC)."
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "Conexão da mensagem."
                          },
                          "conversation_id": {
                            "type": "string",
                            "description": "Conversa da mensagem."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Contato da conversa."
                          },
                          "direction": {
                            "enum": [
                              "inbound",
                              "outbound"
                            ],
                            "type": "string",
                            "description": "`inbound` (recebida) ou `outbound` (enviada)."
                          },
                          "source": {
                            "enum": [
                              "customer",
                              "api",
                              "business_app",
                              "history",
                              "campaign"
                            ],
                            "type": "string",
                            "description": "Origem: `customer`, `api`, `business_app`, `history` ou `campaign`."
                          },
                          "type": {
                            "type": "string",
                            "description": "Tipo do conteúdo, ex.: `text`, `image`."
                          },
                          "status": {
                            "enum": [
                              "received",
                              "queued",
                              "sent",
                              "delivered",
                              "read",
                              "played",
                              "failed",
                              "deleted"
                            ],
                            "type": "string",
                            "description": "Status atual da mensagem."
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID da mensagem na Meta."
                          },
                          "occurred_at": {
                            "type": "string",
                            "description": "Quando a Meta registrou a mensagem (ISO 8601, UTC)."
                          },
                          "status_updated_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última mudança de status (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "created_at",
                          "connection_id",
                          "conversation_id",
                          "contact_id",
                          "direction",
                          "source",
                          "type",
                          "status",
                          "external_id",
                          "occurred_at",
                          "status_updated_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/logs/api-requests": {
      "get": {
        "operationId": "listApiRequestLogs",
        "summary": "Log de chamadas à API",
        "description": "Lista as chamadas à `/v1` feitas com as chaves da organização nos últimos 30 dias. Chave presa a conexões vê só as próprias chamadas. Permissão: `read`.",
        "tags": [
          "logs"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "api_key_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Chave usada na chamada."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status_class",
            "in": "query",
            "schema": {
              "enum": [
                "2xx",
                "4xx",
                "5xx"
              ],
              "type": "string",
              "description": "Só chamadas com status `2xx`, `4xx` ou `5xx`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Início do intervalo (ISO 8601), no máximo 30 dias atrás; padrão = 30 dias atrás."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fim do intervalo (ISO 8601); padrão = agora."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "As chamadas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do registro."
                          },
                          "api_key_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Chave usada na chamada."
                          },
                          "request_id": {
                            "type": "string",
                            "description": "ID da requisição (cabeçalho `X-Request-Id`)."
                          },
                          "method": {
                            "type": "string",
                            "description": "Método HTTP."
                          },
                          "path": {
                            "type": "string",
                            "description": "Caminho chamado, sem a query."
                          },
                          "status": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Status HTTP da resposta."
                          },
                          "duration_ms": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Duração, em milissegundos."
                          },
                          "error_code": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Código do erro, quando a chamada falhou."
                          },
                          "idempotency_key": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "`Idempotency-Key` enviada, se houve."
                          },
                          "ip": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "IP de origem."
                          },
                          "user_agent": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "User-Agent do cliente."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando a chamada foi feita (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "api_key_id",
                          "request_id",
                          "method",
                          "path",
                          "status",
                          "duration_ms",
                          "error_code",
                          "idempotency_key",
                          "ip",
                          "user_agent",
                          "created_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections": {
      "get": {
        "operationId": "listConnections",
        "summary": "Listar conexões",
        "description": "Lista as conexões da organização (números do WhatsApp e, nas próximas fases, contas do Instagram e do Messenger), da mais nova para a mais antiga, com os dados do canal. Chave presa a conexões só vê as suas. Permissão: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending",
                "active",
                "needs_reconnect",
                "restricted",
                "disabled",
                "disconnected"
              ],
              "type": "string",
              "description": "Só conexões com este status."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de conexões.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da conexão (`con_…`).",
                            "examples": [
                              "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "channel": {
                            "enum": [
                              "whatsapp",
                              "instagram",
                              "messenger"
                            ],
                            "type": "string",
                            "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                          },
                          "status": {
                            "enum": [
                              "pending",
                              "active",
                              "needs_reconnect",
                              "restricted",
                              "disabled",
                              "disconnected"
                            ],
                            "type": "string",
                            "description": "Status: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` ou `disconnected`."
                          },
                          "status_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo do status atual, quando há."
                          },
                          "label": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome que a organização deu à conexão."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID na Meta (no WhatsApp, o `phone_number_id`)."
                          },
                          "external_label": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Rótulo vindo da Meta, ex.: o número formatado."
                          },
                          "mode": {
                            "anyOf": [
                              {
                                "enum": [
                                  "coex",
                                  "api_only"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                          },
                          "send_rate_mps": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                          },
                          "connected_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando a conexão ficou ativa (ISO 8601, UTC)."
                          },
                          "last_webhook_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último webhook recebido (ISO 8601, UTC); atualizado no máximo a cada 30 s."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando a conexão foi criada (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última alteração (ISO 8601, UTC)."
                          },
                          "whatsapp": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "phone_number_id": {
                                    "type": "string",
                                    "description": "ID do número na Meta."
                                  },
                                  "messaging_account_id": {
                                    "type": "string",
                                    "description": "Conta do WhatsApp Business (WABA) do número."
                                  },
                                  "mode": {
                                    "enum": [
                                      "coex",
                                      "api_only"
                                    ],
                                    "type": "string",
                                    "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                                  },
                                  "display_phone_number": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Número como a Meta exibe."
                                  },
                                  "verified_name": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nome exibido aprovado."
                                  },
                                  "quality_rating": {
                                    "type": "string",
                                    "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                                  },
                                  "messaging_limit": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Faixa de mensagens da Meta, ex.: `TIER_2K`."
                                  },
                                  "throughput_level": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nível de vazão: `STANDARD`, `HIGH` ou `NOT_APPLICABLE`."
                                  },
                                  "send_rate_mps": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                                  },
                                  "can_send_message": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Se a Meta deixa enviar: `AVAILABLE`, `LIMITED` ou `BLOCKED`."
                                  },
                                  "restriction": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "types": {
                                            "type": "array",
                                            "items": {
                                              "type": "string"
                                            },
                                            "description": "Tipos de restrição informados pela Meta."
                                          },
                                          "until": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ],
                                            "description": "Até quando vale (ISO 8601), se a Meta informou."
                                          },
                                          "remediation": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ],
                                            "description": "O que fazer para sair da restrição."
                                          }
                                        },
                                        "required": [
                                          "types",
                                          "until",
                                          "remediation"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Restrição ativa da conta; `null` sem restrição."
                                  },
                                  "register_status": {
                                    "type": "string",
                                    "description": "Registro na Cloud API: `not_needed`, `pending`, `registered` ou `failed`."
                                  },
                                  "contacts_sync_status": {
                                    "type": "string",
                                    "description": "Sincronização dos contatos da coexistência."
                                  },
                                  "history_sync_status": {
                                    "type": "string",
                                    "description": "Sincronização do histórico da coexistência."
                                  },
                                  "history_sync_progress": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Progresso do histórico, de 0 a 100."
                                  },
                                  "username": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nome de usuário do WhatsApp."
                                  }
                                },
                                "required": [
                                  "phone_number_id",
                                  "messaging_account_id",
                                  "mode",
                                  "display_phone_number",
                                  "verified_name",
                                  "quality_rating",
                                  "messaging_limit",
                                  "throughput_level",
                                  "send_rate_mps",
                                  "can_send_message",
                                  "restriction",
                                  "register_status",
                                  "contacts_sync_status",
                                  "history_sync_status",
                                  "history_sync_progress",
                                  "username"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Dados do WhatsApp; `null` nos outros canais."
                          },
                          "instagram": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "ig_user_id": {
                                    "type": "string",
                                    "description": "ID da conta profissional do Instagram (`ig_user_id`)."
                                  },
                                  "username": {
                                    "type": "string",
                                    "description": "Nome de usuário da conta (@)."
                                  },
                                  "name": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nome exibido da conta."
                                  },
                                  "account_type": {
                                    "type": "string",
                                    "description": "Tipo da conta: `BUSINESS` ou `MEDIA_CREATOR`. Conexões do login unificado informam `BUSINESS` até a pendência 2-20."
                                  },
                                  "scopes": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Permissões concedidas pela Meta."
                                  },
                                  "missing_scopes": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Permissões do Instagram não concedidas; o recurso que depende delas responde `403 instagram_scope_missing` até reconectar."
                                  },
                                  "token_expires_at": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Quando o token vence (ISO 8601, UTC). Sempre nulo no Instagram: o token não vence."
                                  },
                                  "token_refreshed_at": {
                                    "type": "string",
                                    "description": "Quando o token atual foi emitido (conexão ou reconexão) (ISO 8601, UTC)."
                                  },
                                  "followers_count": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Seguidores na última leitura."
                                  },
                                  "publishing_quota": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "quota_usage": {
                                            "type": "integer",
                                            "minimum": -9007199254740991,
                                            "maximum": 9007199254740991,
                                            "description": "Publicações feitas na janela da cota."
                                          },
                                          "quota_total": {
                                            "type": "integer",
                                            "minimum": -9007199254740991,
                                            "maximum": 9007199254740991,
                                            "description": "Publicações permitidas na janela."
                                          },
                                          "quota_duration_s": {
                                            "type": "integer",
                                            "minimum": -9007199254740991,
                                            "maximum": 9007199254740991,
                                            "description": "Duração da janela, em segundos."
                                          },
                                          "checked_at": {
                                            "type": "string",
                                            "description": "Quando a cota foi lida (ISO 8601, UTC)."
                                          }
                                        },
                                        "required": [
                                          "quota_usage",
                                          "quota_total",
                                          "quota_duration_s",
                                          "checked_at"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Cota de publicação na última checagem de saúde; `null` sem a permissão de publicar."
                                  }
                                },
                                "required": [
                                  "ig_user_id",
                                  "username",
                                  "name",
                                  "account_type",
                                  "scopes",
                                  "missing_scopes",
                                  "token_expires_at",
                                  "token_refreshed_at",
                                  "followers_count",
                                  "publishing_quota"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Dados do Instagram; `null` nos outros canais."
                          },
                          "messenger": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "page_id": {
                                    "type": "string",
                                    "description": "ID da Página do Facebook."
                                  },
                                  "page_name": {
                                    "type": "string",
                                    "description": "Nome da Página."
                                  },
                                  "page_category": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Categoria da Página."
                                  },
                                  "tasks": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Tarefas que o usuário que conectou tem na Página (`MESSAGING`, `MANAGE`…)."
                                  },
                                  "scopes": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Permissões concedidas pela Meta."
                                  }
                                },
                                "required": [
                                  "page_id",
                                  "page_name",
                                  "page_category",
                                  "tasks",
                                  "scopes"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Dados da Página do Facebook (Messenger); `null` nos outros canais."
                          }
                        },
                        "required": [
                          "id",
                          "channel",
                          "status",
                          "status_reason",
                          "label",
                          "external_id",
                          "external_label",
                          "mode",
                          "send_rate_mps",
                          "connected_at",
                          "last_webhook_at",
                          "created_at",
                          "updated_at",
                          "whatsapp",
                          "instagram",
                          "messenger"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}": {
      "get": {
        "operationId": "getConnection",
        "summary": "Obter uma conexão",
        "description": "Devolve a conexão com status, modo, velocidade de envio e, no WhatsApp, qualidade, faixa de mensagens, restrições e o estado do registro e da sincronização da coexistência. Permissão: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A conexão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da conexão (`con_…`).",
                      "examples": [
                        "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "active",
                        "needs_reconnect",
                        "restricted",
                        "disabled",
                        "disconnected"
                      ],
                      "type": "string",
                      "description": "Status: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` ou `disconnected`."
                    },
                    "status_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do status atual, quando há."
                    },
                    "label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome que a organização deu à conexão."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID na Meta (no WhatsApp, o `phone_number_id`)."
                    },
                    "external_label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Rótulo vindo da Meta, ex.: o número formatado."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                    },
                    "send_rate_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                    },
                    "connected_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a conexão ficou ativa (ISO 8601, UTC)."
                    },
                    "last_webhook_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último webhook recebido (ISO 8601, UTC); atualizado no máximo a cada 30 s."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a conexão foi criada (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    },
                    "whatsapp": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "phone_number_id": {
                              "type": "string",
                              "description": "ID do número na Meta."
                            },
                            "messaging_account_id": {
                              "type": "string",
                              "description": "Conta do WhatsApp Business (WABA) do número."
                            },
                            "mode": {
                              "enum": [
                                "coex",
                                "api_only"
                              ],
                              "type": "string",
                              "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                            },
                            "display_phone_number": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Número como a Meta exibe."
                            },
                            "verified_name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome exibido aprovado."
                            },
                            "quality_rating": {
                              "type": "string",
                              "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                            },
                            "messaging_limit": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Faixa de mensagens da Meta, ex.: `TIER_2K`."
                            },
                            "throughput_level": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nível de vazão: `STANDARD`, `HIGH` ou `NOT_APPLICABLE`."
                            },
                            "send_rate_mps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                            },
                            "can_send_message": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Se a Meta deixa enviar: `AVAILABLE`, `LIMITED` ou `BLOCKED`."
                            },
                            "restriction": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "types": {
                                      "type": "array",
                                      "items": {
                                        "type": "string"
                                      },
                                      "description": "Tipos de restrição informados pela Meta."
                                    },
                                    "until": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Até quando vale (ISO 8601), se a Meta informou."
                                    },
                                    "remediation": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "O que fazer para sair da restrição."
                                    }
                                  },
                                  "required": [
                                    "types",
                                    "until",
                                    "remediation"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Restrição ativa da conta; `null` sem restrição."
                            },
                            "register_status": {
                              "type": "string",
                              "description": "Registro na Cloud API: `not_needed`, `pending`, `registered` ou `failed`."
                            },
                            "contacts_sync_status": {
                              "type": "string",
                              "description": "Sincronização dos contatos da coexistência."
                            },
                            "history_sync_status": {
                              "type": "string",
                              "description": "Sincronização do histórico da coexistência."
                            },
                            "history_sync_progress": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Progresso do histórico, de 0 a 100."
                            },
                            "username": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome de usuário do WhatsApp."
                            }
                          },
                          "required": [
                            "phone_number_id",
                            "messaging_account_id",
                            "mode",
                            "display_phone_number",
                            "verified_name",
                            "quality_rating",
                            "messaging_limit",
                            "throughput_level",
                            "send_rate_mps",
                            "can_send_message",
                            "restriction",
                            "register_status",
                            "contacts_sync_status",
                            "history_sync_status",
                            "history_sync_progress",
                            "username"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados do WhatsApp; `null` nos outros canais."
                    },
                    "instagram": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ig_user_id": {
                              "type": "string",
                              "description": "ID da conta profissional do Instagram (`ig_user_id`)."
                            },
                            "username": {
                              "type": "string",
                              "description": "Nome de usuário da conta (@)."
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome exibido da conta."
                            },
                            "account_type": {
                              "type": "string",
                              "description": "Tipo da conta: `BUSINESS` ou `MEDIA_CREATOR`. Conexões do login unificado informam `BUSINESS` até a pendência 2-20."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões concedidas pela Meta."
                            },
                            "missing_scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões do Instagram não concedidas; o recurso que depende delas responde `403 instagram_scope_missing` até reconectar."
                            },
                            "token_expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o token vence (ISO 8601, UTC). Sempre nulo no Instagram: o token não vence."
                            },
                            "token_refreshed_at": {
                              "type": "string",
                              "description": "Quando o token atual foi emitido (conexão ou reconexão) (ISO 8601, UTC)."
                            },
                            "followers_count": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Seguidores na última leitura."
                            },
                            "publishing_quota": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "quota_usage": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicações feitas na janela da cota."
                                    },
                                    "quota_total": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicações permitidas na janela."
                                    },
                                    "quota_duration_s": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Duração da janela, em segundos."
                                    },
                                    "checked_at": {
                                      "type": "string",
                                      "description": "Quando a cota foi lida (ISO 8601, UTC)."
                                    }
                                  },
                                  "required": [
                                    "quota_usage",
                                    "quota_total",
                                    "quota_duration_s",
                                    "checked_at"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cota de publicação na última checagem de saúde; `null` sem a permissão de publicar."
                            }
                          },
                          "required": [
                            "ig_user_id",
                            "username",
                            "name",
                            "account_type",
                            "scopes",
                            "missing_scopes",
                            "token_expires_at",
                            "token_refreshed_at",
                            "followers_count",
                            "publishing_quota"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados do Instagram; `null` nos outros canais."
                    },
                    "messenger": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "page_id": {
                              "type": "string",
                              "description": "ID da Página do Facebook."
                            },
                            "page_name": {
                              "type": "string",
                              "description": "Nome da Página."
                            },
                            "page_category": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Categoria da Página."
                            },
                            "tasks": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Tarefas que o usuário que conectou tem na Página (`MESSAGING`, `MANAGE`…)."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões concedidas pela Meta."
                            }
                          },
                          "required": [
                            "page_id",
                            "page_name",
                            "page_category",
                            "tasks",
                            "scopes"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados da Página do Facebook (Messenger); `null` nos outros canais."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "status",
                    "status_reason",
                    "label",
                    "external_id",
                    "external_label",
                    "mode",
                    "send_rate_mps",
                    "connected_at",
                    "last_webhook_at",
                    "created_at",
                    "updated_at",
                    "whatsapp",
                    "instagram",
                    "messenger"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateConnection",
        "summary": "Renomear uma conexão",
        "description": "Troca o nome que a organização dá à conexão (não muda nada na Meta). Permissão: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Nome que a organização deu à conexão."
                  }
                },
                "required": [
                  "label"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A conexão atualizada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da conexão (`con_…`).",
                      "examples": [
                        "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "active",
                        "needs_reconnect",
                        "restricted",
                        "disabled",
                        "disconnected"
                      ],
                      "type": "string",
                      "description": "Status: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` ou `disconnected`."
                    },
                    "status_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do status atual, quando há."
                    },
                    "label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome que a organização deu à conexão."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID na Meta (no WhatsApp, o `phone_number_id`)."
                    },
                    "external_label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Rótulo vindo da Meta, ex.: o número formatado."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                    },
                    "send_rate_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                    },
                    "connected_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a conexão ficou ativa (ISO 8601, UTC)."
                    },
                    "last_webhook_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último webhook recebido (ISO 8601, UTC); atualizado no máximo a cada 30 s."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a conexão foi criada (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    },
                    "whatsapp": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "phone_number_id": {
                              "type": "string",
                              "description": "ID do número na Meta."
                            },
                            "messaging_account_id": {
                              "type": "string",
                              "description": "Conta do WhatsApp Business (WABA) do número."
                            },
                            "mode": {
                              "enum": [
                                "coex",
                                "api_only"
                              ],
                              "type": "string",
                              "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                            },
                            "display_phone_number": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Número como a Meta exibe."
                            },
                            "verified_name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome exibido aprovado."
                            },
                            "quality_rating": {
                              "type": "string",
                              "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                            },
                            "messaging_limit": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Faixa de mensagens da Meta, ex.: `TIER_2K`."
                            },
                            "throughput_level": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nível de vazão: `STANDARD`, `HIGH` ou `NOT_APPLICABLE`."
                            },
                            "send_rate_mps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                            },
                            "can_send_message": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Se a Meta deixa enviar: `AVAILABLE`, `LIMITED` ou `BLOCKED`."
                            },
                            "restriction": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "types": {
                                      "type": "array",
                                      "items": {
                                        "type": "string"
                                      },
                                      "description": "Tipos de restrição informados pela Meta."
                                    },
                                    "until": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Até quando vale (ISO 8601), se a Meta informou."
                                    },
                                    "remediation": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "O que fazer para sair da restrição."
                                    }
                                  },
                                  "required": [
                                    "types",
                                    "until",
                                    "remediation"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Restrição ativa da conta; `null` sem restrição."
                            },
                            "register_status": {
                              "type": "string",
                              "description": "Registro na Cloud API: `not_needed`, `pending`, `registered` ou `failed`."
                            },
                            "contacts_sync_status": {
                              "type": "string",
                              "description": "Sincronização dos contatos da coexistência."
                            },
                            "history_sync_status": {
                              "type": "string",
                              "description": "Sincronização do histórico da coexistência."
                            },
                            "history_sync_progress": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Progresso do histórico, de 0 a 100."
                            },
                            "username": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome de usuário do WhatsApp."
                            }
                          },
                          "required": [
                            "phone_number_id",
                            "messaging_account_id",
                            "mode",
                            "display_phone_number",
                            "verified_name",
                            "quality_rating",
                            "messaging_limit",
                            "throughput_level",
                            "send_rate_mps",
                            "can_send_message",
                            "restriction",
                            "register_status",
                            "contacts_sync_status",
                            "history_sync_status",
                            "history_sync_progress",
                            "username"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados do WhatsApp; `null` nos outros canais."
                    },
                    "instagram": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ig_user_id": {
                              "type": "string",
                              "description": "ID da conta profissional do Instagram (`ig_user_id`)."
                            },
                            "username": {
                              "type": "string",
                              "description": "Nome de usuário da conta (@)."
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome exibido da conta."
                            },
                            "account_type": {
                              "type": "string",
                              "description": "Tipo da conta: `BUSINESS` ou `MEDIA_CREATOR`. Conexões do login unificado informam `BUSINESS` até a pendência 2-20."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões concedidas pela Meta."
                            },
                            "missing_scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões do Instagram não concedidas; o recurso que depende delas responde `403 instagram_scope_missing` até reconectar."
                            },
                            "token_expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o token vence (ISO 8601, UTC). Sempre nulo no Instagram: o token não vence."
                            },
                            "token_refreshed_at": {
                              "type": "string",
                              "description": "Quando o token atual foi emitido (conexão ou reconexão) (ISO 8601, UTC)."
                            },
                            "followers_count": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Seguidores na última leitura."
                            },
                            "publishing_quota": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "quota_usage": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicações feitas na janela da cota."
                                    },
                                    "quota_total": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicações permitidas na janela."
                                    },
                                    "quota_duration_s": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Duração da janela, em segundos."
                                    },
                                    "checked_at": {
                                      "type": "string",
                                      "description": "Quando a cota foi lida (ISO 8601, UTC)."
                                    }
                                  },
                                  "required": [
                                    "quota_usage",
                                    "quota_total",
                                    "quota_duration_s",
                                    "checked_at"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cota de publicação na última checagem de saúde; `null` sem a permissão de publicar."
                            }
                          },
                          "required": [
                            "ig_user_id",
                            "username",
                            "name",
                            "account_type",
                            "scopes",
                            "missing_scopes",
                            "token_expires_at",
                            "token_refreshed_at",
                            "followers_count",
                            "publishing_quota"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados do Instagram; `null` nos outros canais."
                    },
                    "messenger": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "page_id": {
                              "type": "string",
                              "description": "ID da Página do Facebook."
                            },
                            "page_name": {
                              "type": "string",
                              "description": "Nome da Página."
                            },
                            "page_category": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Categoria da Página."
                            },
                            "tasks": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Tarefas que o usuário que conectou tem na Página (`MESSAGING`, `MANAGE`…)."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões concedidas pela Meta."
                            }
                          },
                          "required": [
                            "page_id",
                            "page_name",
                            "page_category",
                            "tasks",
                            "scopes"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados da Página do Facebook (Messenger); `null` nos outros canais."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "status",
                    "status_reason",
                    "label",
                    "external_id",
                    "external_label",
                    "mode",
                    "send_rate_mps",
                    "connected_at",
                    "last_webhook_at",
                    "created_at",
                    "updated_at",
                    "whatsapp",
                    "instagram",
                    "messenger"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/disconnect": {
      "post": {
        "operationId": "disconnectConnection",
        "summary": "Desconectar",
        "description": "Desconecta a conexão: a credencial é revogada, os webhooks deixam de chegar e o número sai da cobrança. No modo só API, `deregister: true` também tira o número da Cloud API. Falhas do lado da Meta não impedem a desconexão e voltam em `warnings`. Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "deregister": {
                    "type": "boolean",
                    "description": "Só API: também tira o número da Cloud API."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A conexão desconectada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da conexão (`con_…`).",
                      "examples": [
                        "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "active",
                        "needs_reconnect",
                        "restricted",
                        "disabled",
                        "disconnected"
                      ],
                      "type": "string",
                      "description": "Status: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` ou `disconnected`."
                    },
                    "status_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do status atual, quando há."
                    },
                    "label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome que a organização deu à conexão."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID na Meta (no WhatsApp, o `phone_number_id`)."
                    },
                    "external_label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Rótulo vindo da Meta, ex.: o número formatado."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                    },
                    "send_rate_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                    },
                    "connected_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a conexão ficou ativa (ISO 8601, UTC)."
                    },
                    "last_webhook_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último webhook recebido (ISO 8601, UTC); atualizado no máximo a cada 30 s."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a conexão foi criada (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    },
                    "whatsapp": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "phone_number_id": {
                              "type": "string",
                              "description": "ID do número na Meta."
                            },
                            "messaging_account_id": {
                              "type": "string",
                              "description": "Conta do WhatsApp Business (WABA) do número."
                            },
                            "mode": {
                              "enum": [
                                "coex",
                                "api_only"
                              ],
                              "type": "string",
                              "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                            },
                            "display_phone_number": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Número como a Meta exibe."
                            },
                            "verified_name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome exibido aprovado."
                            },
                            "quality_rating": {
                              "type": "string",
                              "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                            },
                            "messaging_limit": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Faixa de mensagens da Meta, ex.: `TIER_2K`."
                            },
                            "throughput_level": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nível de vazão: `STANDARD`, `HIGH` ou `NOT_APPLICABLE`."
                            },
                            "send_rate_mps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                            },
                            "can_send_message": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Se a Meta deixa enviar: `AVAILABLE`, `LIMITED` ou `BLOCKED`."
                            },
                            "restriction": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "types": {
                                      "type": "array",
                                      "items": {
                                        "type": "string"
                                      },
                                      "description": "Tipos de restrição informados pela Meta."
                                    },
                                    "until": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Até quando vale (ISO 8601), se a Meta informou."
                                    },
                                    "remediation": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "O que fazer para sair da restrição."
                                    }
                                  },
                                  "required": [
                                    "types",
                                    "until",
                                    "remediation"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Restrição ativa da conta; `null` sem restrição."
                            },
                            "register_status": {
                              "type": "string",
                              "description": "Registro na Cloud API: `not_needed`, `pending`, `registered` ou `failed`."
                            },
                            "contacts_sync_status": {
                              "type": "string",
                              "description": "Sincronização dos contatos da coexistência."
                            },
                            "history_sync_status": {
                              "type": "string",
                              "description": "Sincronização do histórico da coexistência."
                            },
                            "history_sync_progress": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Progresso do histórico, de 0 a 100."
                            },
                            "username": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome de usuário do WhatsApp."
                            }
                          },
                          "required": [
                            "phone_number_id",
                            "messaging_account_id",
                            "mode",
                            "display_phone_number",
                            "verified_name",
                            "quality_rating",
                            "messaging_limit",
                            "throughput_level",
                            "send_rate_mps",
                            "can_send_message",
                            "restriction",
                            "register_status",
                            "contacts_sync_status",
                            "history_sync_status",
                            "history_sync_progress",
                            "username"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados do WhatsApp; `null` nos outros canais."
                    },
                    "instagram": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ig_user_id": {
                              "type": "string",
                              "description": "ID da conta profissional do Instagram (`ig_user_id`)."
                            },
                            "username": {
                              "type": "string",
                              "description": "Nome de usuário da conta (@)."
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome exibido da conta."
                            },
                            "account_type": {
                              "type": "string",
                              "description": "Tipo da conta: `BUSINESS` ou `MEDIA_CREATOR`. Conexões do login unificado informam `BUSINESS` até a pendência 2-20."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões concedidas pela Meta."
                            },
                            "missing_scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões do Instagram não concedidas; o recurso que depende delas responde `403 instagram_scope_missing` até reconectar."
                            },
                            "token_expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o token vence (ISO 8601, UTC). Sempre nulo no Instagram: o token não vence."
                            },
                            "token_refreshed_at": {
                              "type": "string",
                              "description": "Quando o token atual foi emitido (conexão ou reconexão) (ISO 8601, UTC)."
                            },
                            "followers_count": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Seguidores na última leitura."
                            },
                            "publishing_quota": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "quota_usage": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicações feitas na janela da cota."
                                    },
                                    "quota_total": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicações permitidas na janela."
                                    },
                                    "quota_duration_s": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Duração da janela, em segundos."
                                    },
                                    "checked_at": {
                                      "type": "string",
                                      "description": "Quando a cota foi lida (ISO 8601, UTC)."
                                    }
                                  },
                                  "required": [
                                    "quota_usage",
                                    "quota_total",
                                    "quota_duration_s",
                                    "checked_at"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cota de publicação na última checagem de saúde; `null` sem a permissão de publicar."
                            }
                          },
                          "required": [
                            "ig_user_id",
                            "username",
                            "name",
                            "account_type",
                            "scopes",
                            "missing_scopes",
                            "token_expires_at",
                            "token_refreshed_at",
                            "followers_count",
                            "publishing_quota"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados do Instagram; `null` nos outros canais."
                    },
                    "messenger": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "page_id": {
                              "type": "string",
                              "description": "ID da Página do Facebook."
                            },
                            "page_name": {
                              "type": "string",
                              "description": "Nome da Página."
                            },
                            "page_category": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Categoria da Página."
                            },
                            "tasks": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Tarefas que o usuário que conectou tem na Página (`MESSAGING`, `MANAGE`…)."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões concedidas pela Meta."
                            }
                          },
                          "required": [
                            "page_id",
                            "page_name",
                            "page_category",
                            "tasks",
                            "scopes"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados da Página do Facebook (Messenger); `null` nos outros canais."
                    },
                    "warnings": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Falhas do lado da Meta que não impediram a desconexão."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "status",
                    "status_reason",
                    "label",
                    "external_id",
                    "external_label",
                    "mode",
                    "send_rate_mps",
                    "connected_at",
                    "last_webhook_at",
                    "created_at",
                    "updated_at",
                    "whatsapp",
                    "instagram",
                    "messenger",
                    "warnings"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/api-keys": {
      "get": {
        "operationId": "listConnectionApiKeys",
        "summary": "Listar chaves de uma conexão",
        "description": "Lista as chaves de API presas a esta conexão (as chaves de organização não aparecem). Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador da conexão."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "As chaves da conexão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Identificador da chave."
                          },
                          "name": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome da chave (até 32 caracteres)."
                          },
                          "start": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Início visível da chave, para identificá-la."
                          },
                          "permissions": {
                            "type": "array",
                            "items": {
                              "enum": [
                                "send",
                                "read",
                                "templates",
                                "commerce",
                                "admin"
                              ],
                              "type": "string"
                            },
                            "description": "Permissões da chave (`admin` implica as outras)."
                          },
                          "enabled": {
                            "type": "boolean",
                            "description": "Se a chave está ativa."
                          },
                          "expires_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando a chave expira; `null` = não expira."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando a chave foi criada."
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "start",
                          "permissions",
                          "enabled",
                          "expires_at",
                          "created_at"
                        ]
                      },
                      "description": "As chaves da conexão."
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createConnectionApiKey",
        "summary": "Criar chave de uma conexão",
        "description": "Cria uma chave presa a esta conexão (prefixo `mjc_`): ela envia sem `connection_id` e não acessa rotas de organização. O segredo (`key`) aparece só nesta resposta. Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador da conexão."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 32,
                    "description": "Nome da chave (até 32 caracteres)."
                  },
                  "permissions": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "enum": [
                        "send",
                        "read",
                        "templates",
                        "commerce",
                        "admin"
                      ],
                      "type": "string"
                    },
                    "description": "Permissões da chave (`admin` implica as outras)."
                  },
                  "expires_in_days": {
                    "anyOf": [
                      {
                        "type": "null"
                      },
                      {
                        "const": 30
                      },
                      {
                        "const": 90
                      },
                      {
                        "const": 180
                      },
                      {
                        "const": 365
                      }
                    ],
                    "default": null,
                    "description": "Validade em dias (`null` = não expira). Valores aceitos: 30, 90, 180 ou 365."
                  },
                  "rate_per_minute": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 6000,
                    "default": 600,
                    "description": "Limite de requisições por minuto da chave."
                  }
                },
                "required": [
                  "name",
                  "permissions"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A chave criada, com o segredo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Identificador da chave."
                    },
                    "name": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome da chave (até 32 caracteres)."
                    },
                    "start": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início visível da chave, para identificá-la."
                    },
                    "permissions": {
                      "type": "array",
                      "items": {
                        "enum": [
                          "send",
                          "read",
                          "templates",
                          "commerce",
                          "admin"
                        ],
                        "type": "string"
                      },
                      "description": "Permissões da chave (`admin` implica as outras)."
                    },
                    "enabled": {
                      "type": "boolean",
                      "description": "Se a chave está ativa."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a chave expira; `null` = não expira."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a chave foi criada."
                    },
                    "key": {
                      "type": "string",
                      "description": "O segredo da chave. Aparece só na criação: guarde-o."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "start",
                    "permissions",
                    "enabled",
                    "expires_at",
                    "created_at",
                    "key"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api-keys/{id}": {
      "delete": {
        "operationId": "deleteApiKey",
        "summary": "Excluir uma chave de API",
        "description": "Apaga a chave de API (de organização ou de conexão) e ela para de funcionar na hora. Permissão: `admin`. Exige chave da organização; uma chave presa a conexões só alcança chaves dentro delas.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador da chave."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A chave excluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Identificador da chave."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api-keys/{id}/rotate": {
      "post": {
        "operationId": "rotateApiKey",
        "summary": "Rotacionar uma chave de API",
        "description": "Cria uma chave nova com o mesmo nome, permissões, escopo e limite, e mantém a antiga por `grace` (`24h`, padrão, ou `now`, expira na hora). O segredo novo (`key`) aparece só nesta resposta. Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador da chave."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "grace": {
                    "enum": [
                      "now",
                      "24h"
                    ],
                    "type": "string",
                    "default": "24h",
                    "description": "Carência da chave antiga: `24h` (padrão) ou `now`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A chave nova, com o segredo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Identificador da chave."
                    },
                    "name": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome da chave (até 32 caracteres)."
                    },
                    "start": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início visível da chave, para identificá-la."
                    },
                    "permissions": {
                      "type": "array",
                      "items": {
                        "enum": [
                          "send",
                          "read",
                          "templates",
                          "commerce",
                          "admin"
                        ],
                        "type": "string"
                      },
                      "description": "Permissões da chave (`admin` implica as outras)."
                    },
                    "enabled": {
                      "type": "boolean",
                      "description": "Se a chave está ativa."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a chave expira; `null` = não expira."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a chave foi criada."
                    },
                    "key": {
                      "type": "string",
                      "description": "O segredo da chave. Aparece só na criação: guarde-o."
                    },
                    "previous_key_expires_at": {
                      "type": "string",
                      "description": "Quando a chave antiga deixa de valer (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "start",
                    "permissions",
                    "enabled",
                    "expires_at",
                    "created_at",
                    "key",
                    "previous_key_expires_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/refresh-health": {
      "post": {
        "operationId": "refreshConnectionHealth",
        "summary": "Atualizar a saúde",
        "description": "Lê agora na Meta a qualidade, a faixa de mensagens, a velocidade e o `can_send_message` do número (o Messajo já faz isso a cada 15 minutos). Token inválido marca a conexão como `needs_reconnect`. Permissão: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A conexão com a leitura nova.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da conexão (`con_…`).",
                      "examples": [
                        "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "active",
                        "needs_reconnect",
                        "restricted",
                        "disabled",
                        "disconnected"
                      ],
                      "type": "string",
                      "description": "Status: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` ou `disconnected`."
                    },
                    "status_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do status atual, quando há."
                    },
                    "label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome que a organização deu à conexão."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID na Meta (no WhatsApp, o `phone_number_id`)."
                    },
                    "external_label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Rótulo vindo da Meta, ex.: o número formatado."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                    },
                    "send_rate_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                    },
                    "connected_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a conexão ficou ativa (ISO 8601, UTC)."
                    },
                    "last_webhook_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último webhook recebido (ISO 8601, UTC); atualizado no máximo a cada 30 s."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a conexão foi criada (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    },
                    "whatsapp": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "phone_number_id": {
                              "type": "string",
                              "description": "ID do número na Meta."
                            },
                            "messaging_account_id": {
                              "type": "string",
                              "description": "Conta do WhatsApp Business (WABA) do número."
                            },
                            "mode": {
                              "enum": [
                                "coex",
                                "api_only"
                              ],
                              "type": "string",
                              "description": "Modo no WhatsApp: `coex` (coexistência com o app) ou `api_only`."
                            },
                            "display_phone_number": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Número como a Meta exibe."
                            },
                            "verified_name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome exibido aprovado."
                            },
                            "quality_rating": {
                              "type": "string",
                              "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                            },
                            "messaging_limit": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Faixa de mensagens da Meta, ex.: `TIER_2K`."
                            },
                            "throughput_level": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nível de vazão: `STANDARD`, `HIGH` ou `NOT_APPLICABLE`."
                            },
                            "send_rate_mps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Mensagens por segundo que o Messajo deixa sair por esta conexão."
                            },
                            "can_send_message": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Se a Meta deixa enviar: `AVAILABLE`, `LIMITED` ou `BLOCKED`."
                            },
                            "restriction": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "types": {
                                      "type": "array",
                                      "items": {
                                        "type": "string"
                                      },
                                      "description": "Tipos de restrição informados pela Meta."
                                    },
                                    "until": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Até quando vale (ISO 8601), se a Meta informou."
                                    },
                                    "remediation": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "O que fazer para sair da restrição."
                                    }
                                  },
                                  "required": [
                                    "types",
                                    "until",
                                    "remediation"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Restrição ativa da conta; `null` sem restrição."
                            },
                            "register_status": {
                              "type": "string",
                              "description": "Registro na Cloud API: `not_needed`, `pending`, `registered` ou `failed`."
                            },
                            "contacts_sync_status": {
                              "type": "string",
                              "description": "Sincronização dos contatos da coexistência."
                            },
                            "history_sync_status": {
                              "type": "string",
                              "description": "Sincronização do histórico da coexistência."
                            },
                            "history_sync_progress": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Progresso do histórico, de 0 a 100."
                            },
                            "username": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome de usuário do WhatsApp."
                            }
                          },
                          "required": [
                            "phone_number_id",
                            "messaging_account_id",
                            "mode",
                            "display_phone_number",
                            "verified_name",
                            "quality_rating",
                            "messaging_limit",
                            "throughput_level",
                            "send_rate_mps",
                            "can_send_message",
                            "restriction",
                            "register_status",
                            "contacts_sync_status",
                            "history_sync_status",
                            "history_sync_progress",
                            "username"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados do WhatsApp; `null` nos outros canais."
                    },
                    "instagram": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ig_user_id": {
                              "type": "string",
                              "description": "ID da conta profissional do Instagram (`ig_user_id`)."
                            },
                            "username": {
                              "type": "string",
                              "description": "Nome de usuário da conta (@)."
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nome exibido da conta."
                            },
                            "account_type": {
                              "type": "string",
                              "description": "Tipo da conta: `BUSINESS` ou `MEDIA_CREATOR`. Conexões do login unificado informam `BUSINESS` até a pendência 2-20."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões concedidas pela Meta."
                            },
                            "missing_scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões do Instagram não concedidas; o recurso que depende delas responde `403 instagram_scope_missing` até reconectar."
                            },
                            "token_expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o token vence (ISO 8601, UTC). Sempre nulo no Instagram: o token não vence."
                            },
                            "token_refreshed_at": {
                              "type": "string",
                              "description": "Quando o token atual foi emitido (conexão ou reconexão) (ISO 8601, UTC)."
                            },
                            "followers_count": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Seguidores na última leitura."
                            },
                            "publishing_quota": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "quota_usage": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicações feitas na janela da cota."
                                    },
                                    "quota_total": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicações permitidas na janela."
                                    },
                                    "quota_duration_s": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Duração da janela, em segundos."
                                    },
                                    "checked_at": {
                                      "type": "string",
                                      "description": "Quando a cota foi lida (ISO 8601, UTC)."
                                    }
                                  },
                                  "required": [
                                    "quota_usage",
                                    "quota_total",
                                    "quota_duration_s",
                                    "checked_at"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cota de publicação na última checagem de saúde; `null` sem a permissão de publicar."
                            }
                          },
                          "required": [
                            "ig_user_id",
                            "username",
                            "name",
                            "account_type",
                            "scopes",
                            "missing_scopes",
                            "token_expires_at",
                            "token_refreshed_at",
                            "followers_count",
                            "publishing_quota"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados do Instagram; `null` nos outros canais."
                    },
                    "messenger": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "page_id": {
                              "type": "string",
                              "description": "ID da Página do Facebook."
                            },
                            "page_name": {
                              "type": "string",
                              "description": "Nome da Página."
                            },
                            "page_category": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Categoria da Página."
                            },
                            "tasks": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Tarefas que o usuário que conectou tem na Página (`MESSAGING`, `MANAGE`…)."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permissões concedidas pela Meta."
                            }
                          },
                          "required": [
                            "page_id",
                            "page_name",
                            "page_category",
                            "tasks",
                            "scopes"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dados da Página do Facebook (Messenger); `null` nos outros canais."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "status",
                    "status_reason",
                    "label",
                    "external_id",
                    "external_label",
                    "mode",
                    "send_rate_mps",
                    "connected_at",
                    "last_webhook_at",
                    "created_at",
                    "updated_at",
                    "whatsapp",
                    "instagram",
                    "messenger"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/profile": {
      "get": {
        "operationId": "getConnectionProfile",
        "summary": "Obter o perfil comercial",
        "description": "Devolve o perfil comercial do número na Meta (sobre, endereço, descrição, e-mail, sites, setor e foto). Permissão: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O perfil comercial.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "about": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto \"sobre\" do perfil."
                    },
                    "address": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Endereço."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição da empresa."
                    },
                    "email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "E-mail de contato."
                    },
                    "websites": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Até 2 sites."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Setor da empresa, ex.: `RETAIL`."
                    },
                    "profile_picture_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Link da foto do perfil na Meta."
                    }
                  },
                  "required": [
                    "about",
                    "address",
                    "description",
                    "email",
                    "websites",
                    "vertical",
                    "profile_picture_url"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateConnectionProfile",
        "summary": "Editar o perfil comercial",
        "description": "Altera os campos enviados do perfil comercial. A foto vem de uma mídia enviada antes por `POST /media`. Na coexistência a Meta não deixa editar pela API: a resposta é `422 coex_not_supported` (edite no app do celular). Permissão: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "about": {
                    "type": "string",
                    "description": "Texto \"sobre\" do perfil."
                  },
                  "address": {
                    "type": "string",
                    "description": "Endereço."
                  },
                  "description": {
                    "type": "string",
                    "description": "Descrição da empresa."
                  },
                  "email": {
                    "type": "string",
                    "description": "E-mail de contato."
                  },
                  "websites": {
                    "type": "array",
                    "maxItems": 2,
                    "items": {
                      "type": "string"
                    },
                    "description": "Até 2 sites."
                  },
                  "vertical": {
                    "enum": [
                      "UNDEFINED",
                      "OTHER",
                      "AUTO",
                      "BEAUTY",
                      "APPAREL",
                      "EDU",
                      "ENTERTAIN",
                      "EVENT_PLAN",
                      "FINANCE",
                      "GROCERY",
                      "GOVT",
                      "HOTEL",
                      "HEALTH",
                      "NONPROFIT",
                      "PROF_SERVICES",
                      "RETAIL",
                      "TRAVEL",
                      "RESTAURANT",
                      "NOT_A_BIZ"
                    ],
                    "type": "string",
                    "description": "Setor da empresa, ex.: `RETAIL`."
                  },
                  "profile_picture_media_id": {
                    "type": "string",
                    "description": "Mídia (`med_…`) enviada por `POST /media` para virar a foto."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O perfil comercial atualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "about": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto \"sobre\" do perfil."
                    },
                    "address": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Endereço."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição da empresa."
                    },
                    "email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "E-mail de contato."
                    },
                    "websites": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Até 2 sites."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Setor da empresa, ex.: `RETAIL`."
                    },
                    "profile_picture_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Link da foto do perfil na Meta."
                    }
                  },
                  "required": [
                    "about",
                    "address",
                    "description",
                    "email",
                    "websites",
                    "vertical",
                    "profile_picture_url"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/display-name": {
      "post": {
        "operationId": "requestDisplayName",
        "summary": "Pedir novo nome exibido",
        "description": "Pede à Meta um nome exibido novo; ele passa por revisão e o status sai em `new_name_status`. Na coexistência: `422 coex_not_supported`. Permissão: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Nome exibido pedido."
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O status do pedido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "new_name_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status da revisão do nome novo na Meta."
                    }
                  },
                  "required": [
                    "new_name_status"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/username": {
      "get": {
        "operationId": "getUsername",
        "summary": "Obter o nome de usuário",
        "description": "Devolve o nome de usuário do WhatsApp do número e o status dele na Meta. Permissão: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O nome de usuário e o status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "username": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome de usuário; `null` quando não há."
                    },
                    "status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status do nome de usuário na Meta."
                    }
                  },
                  "required": [
                    "username",
                    "status"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "put": {
        "operationId": "setUsername",
        "summary": "Definir o nome de usuário",
        "description": "Define ou troca o nome de usuário do número (3 a 35 caracteres: letras, números, `.` e `_`). Na coexistência: `422 coex_not_supported`. Permissão: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": {
                    "type": "string",
                    "description": "Nome de usuário; `null` quando não há."
                  }
                },
                "required": [
                  "username"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O nome de usuário e o status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "username": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome de usuário; `null` quando não há."
                    },
                    "status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status do nome de usuário na Meta."
                    }
                  },
                  "required": [
                    "username",
                    "status"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteUsername",
        "summary": "Remover o nome de usuário",
        "description": "Remove o nome de usuário do número. Na coexistência: `422 coex_not_supported`. Permissão: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O nome de usuário (vazio) e o status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "username": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome de usuário; `null` quando não há."
                    },
                    "status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status do nome de usuário na Meta."
                    }
                  },
                  "required": [
                    "username",
                    "status"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/username/suggestions": {
      "get": {
        "operationId": "listUsernameSuggestions",
        "summary": "Sugestões de nome de usuário",
        "description": "Nomes de usuário livres que a Meta sugere para o número. Permissão: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "As sugestões.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "suggestions": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Nomes de usuário sugeridos."
                    }
                  },
                  "required": [
                    "suggestions"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/messages": {
      "post": {
        "operationId": "sendMessage",
        "summary": "Enviar mensagem",
        "description": "Envia uma mensagem por uma conexão. O corpo muda por canal (veja a união abaixo). WhatsApp: texto, mídia, template, interativa, reação, localização, contatos e figurinha. Instagram e Messenger: `text` (com `quick_replies`), `image`, `images` (2 a 10, só Instagram), `video`, `audio`, `document`, `like` (só Instagram), `reaction`, `share` (post, só Instagram), `buttons` e `cards`. Tipo que o canal não tem: `422 type_not_supported_by_channel`. Fora da janela de 24 h: WhatsApp só template; Instagram e Messenger aceitam `tag: \"human_agent\"` até 7 dias depois da última mensagem do contato, **só para resposta de uma pessoa** (política da Meta; nunca em automação), e depois disso `422 human_agent_window_closed`. Sem a tag: `422 outside_service_window`. Cada conexão tem um limite de mensagens por segundo; acima dele a resposta é `429 connection_rate_limited` com `retry_after_ms`. Use `Idempotency-Key` para repetir sem duplicar: se a Meta não respondeu se aceitou (`502 meta_unknown_outcome`), o Messajo não reenvia sozinho. Permissão: `send`.",
        "tags": [
          "messages"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "anyOf": [
                  {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "text"
                          },
                          "text": {
                            "type": "object",
                            "properties": {
                              "body": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 4096
                              },
                              "preview_url": {
                                "type": "boolean"
                              }
                            },
                            "required": [
                              "body"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "text"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "image"
                          },
                          "image": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              },
                              "caption": {
                                "type": "string",
                                "maxLength": 1024
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "image"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "video"
                          },
                          "video": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              },
                              "caption": {
                                "type": "string",
                                "maxLength": 1024
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "video"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "document"
                          },
                          "document": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              },
                              "caption": {
                                "type": "string",
                                "maxLength": 1024
                              },
                              "filename": {
                                "type": "string",
                                "maxLength": 240
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "document"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "audio"
                          },
                          "audio": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              },
                              "voice": {
                                "type": "boolean"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "audio"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "sticker"
                          },
                          "sticker": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "sticker"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "template"
                          },
                          "template": {
                            "type": "object",
                            "properties": {
                              "name": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 512
                              },
                              "language": {
                                "type": "string",
                                "minLength": 2,
                                "maxLength": 16
                              },
                              "components": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "propertyNames": {
                                    "type": "string"
                                  },
                                  "additionalProperties": {}
                                }
                              }
                            },
                            "required": [
                              "name",
                              "language"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "template"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "interactive"
                          },
                          "interactive": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "button"
                                  },
                                  "header": {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "enum": [
                                          "text",
                                          "image",
                                          "video",
                                          "document"
                                        ],
                                        "type": "string"
                                      },
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "type"
                                    ],
                                    "additionalProperties": {}
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "buttons": {
                                        "type": "array",
                                        "minItems": 1,
                                        "maxItems": 3,
                                        "items": {
                                          "type": "object",
                                          "properties": {
                                            "type": {
                                              "const": "reply"
                                            },
                                            "reply": {
                                              "type": "object",
                                              "properties": {
                                                "id": {
                                                  "type": "string",
                                                  "minLength": 1,
                                                  "maxLength": 256
                                                },
                                                "title": {
                                                  "type": "string",
                                                  "minLength": 1,
                                                  "maxLength": 20
                                                }
                                              },
                                              "required": [
                                                "id",
                                                "title"
                                              ]
                                            }
                                          },
                                          "required": [
                                            "type",
                                            "reply"
                                          ],
                                          "additionalProperties": {}
                                        }
                                      }
                                    },
                                    "required": [
                                      "buttons"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "list"
                                  },
                                  "header": {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "enum": [
                                          "text",
                                          "image",
                                          "video",
                                          "document"
                                        ],
                                        "type": "string"
                                      },
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "type"
                                    ],
                                    "additionalProperties": {}
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "button": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 20
                                      },
                                      "sections": {
                                        "type": "array",
                                        "minItems": 1,
                                        "maxItems": 10,
                                        "items": {
                                          "type": "object",
                                          "properties": {
                                            "title": {
                                              "type": "string",
                                              "maxLength": 24
                                            },
                                            "rows": {
                                              "type": "array",
                                              "minItems": 1,
                                              "items": {
                                                "type": "object",
                                                "properties": {
                                                  "id": {
                                                    "type": "string",
                                                    "minLength": 1,
                                                    "maxLength": 200
                                                  },
                                                  "title": {
                                                    "type": "string",
                                                    "minLength": 1,
                                                    "maxLength": 24
                                                  },
                                                  "description": {
                                                    "type": "string",
                                                    "maxLength": 72
                                                  }
                                                },
                                                "required": [
                                                  "id",
                                                  "title"
                                                ],
                                                "additionalProperties": {}
                                              }
                                            }
                                          },
                                          "required": [
                                            "rows"
                                          ],
                                          "additionalProperties": {}
                                        }
                                      }
                                    },
                                    "required": [
                                      "button",
                                      "sections"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "cta_url"
                                  },
                                  "header": {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "enum": [
                                          "text",
                                          "image",
                                          "video",
                                          "document"
                                        ],
                                        "type": "string"
                                      },
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "type"
                                    ],
                                    "additionalProperties": {}
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "name": {
                                        "const": "cta_url"
                                      },
                                      "parameters": {
                                        "type": "object",
                                        "properties": {
                                          "display_text": {
                                            "type": "string",
                                            "minLength": 1,
                                            "maxLength": 20
                                          },
                                          "url": {
                                            "type": "string",
                                            "format": "uri"
                                          }
                                        },
                                        "required": [
                                          "display_text",
                                          "url"
                                        ]
                                      }
                                    },
                                    "required": [
                                      "name",
                                      "parameters"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "location_request_message"
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "name": {
                                        "const": "send_location"
                                      }
                                    },
                                    "required": [
                                      "name"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "flow"
                                  },
                                  "header": {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "enum": [
                                          "text",
                                          "image",
                                          "video",
                                          "document"
                                        ],
                                        "type": "string"
                                      },
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "type"
                                    ],
                                    "additionalProperties": {}
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "name": {
                                        "const": "flow"
                                      },
                                      "parameters": {
                                        "type": "object",
                                        "properties": {
                                          "flow_token": {
                                            "type": "string",
                                            "minLength": 1,
                                            "maxLength": 512
                                          },
                                          "flow_id": {
                                            "type": "string",
                                            "minLength": 1,
                                            "maxLength": 64
                                          },
                                          "flow_cta": {
                                            "type": "string",
                                            "minLength": 1,
                                            "maxLength": 20
                                          },
                                          "flow_action": {
                                            "enum": [
                                              "navigate",
                                              "data_exchange"
                                            ],
                                            "type": "string"
                                          },
                                          "flow_message_version": {
                                            "type": "string",
                                            "maxLength": 16
                                          },
                                          "flow_action_payload": {
                                            "type": "object",
                                            "properties": {
                                              "screen": {
                                                "type": "string",
                                                "minLength": 1,
                                                "maxLength": 256
                                              },
                                              "data": {
                                                "type": "object",
                                                "propertyNames": {
                                                  "type": "string"
                                                },
                                                "additionalProperties": {}
                                              }
                                            },
                                            "required": [
                                              "screen"
                                            ],
                                            "additionalProperties": {}
                                          },
                                          "mode": {
                                            "enum": [
                                              "draft",
                                              "published"
                                            ],
                                            "type": "string"
                                          }
                                        },
                                        "required": [
                                          "flow_id",
                                          "flow_cta",
                                          "flow_action"
                                        ],
                                        "additionalProperties": {}
                                      }
                                    },
                                    "required": [
                                      "name",
                                      "parameters"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "product"
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "catalog_id": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 128
                                      },
                                      "product_retailer_id": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 128
                                      }
                                    },
                                    "required": [
                                      "catalog_id",
                                      "product_retailer_id"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "product_list"
                                  },
                                  "header": {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "const": "text"
                                      },
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "type",
                                      "text"
                                    ]
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "catalog_id": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 128
                                      },
                                      "sections": {
                                        "type": "array",
                                        "minItems": 1,
                                        "maxItems": 10,
                                        "items": {
                                          "type": "object",
                                          "properties": {
                                            "title": {
                                              "type": "string",
                                              "minLength": 1,
                                              "maxLength": 24
                                            },
                                            "product_items": {
                                              "type": "array",
                                              "minItems": 1,
                                              "items": {
                                                "type": "object",
                                                "properties": {
                                                  "product_retailer_id": {
                                                    "type": "string",
                                                    "minLength": 1,
                                                    "maxLength": 128
                                                  }
                                                },
                                                "required": [
                                                  "product_retailer_id"
                                                ]
                                              }
                                            }
                                          },
                                          "required": [
                                            "title",
                                            "product_items"
                                          ],
                                          "additionalProperties": {}
                                        }
                                      }
                                    },
                                    "required": [
                                      "catalog_id",
                                      "sections"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "header",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "catalog_message"
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "name": {
                                        "const": "catalog_message"
                                      },
                                      "parameters": {
                                        "type": "object",
                                        "properties": {
                                          "thumbnail_product_retailer_id": {
                                            "type": "string",
                                            "minLength": 1,
                                            "maxLength": 128
                                          }
                                        },
                                        "required": [
                                          "thumbnail_product_retailer_id"
                                        ],
                                        "additionalProperties": {}
                                      }
                                    },
                                    "required": [
                                      "name"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "order_details"
                                  },
                                  "header": {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "enum": [
                                          "text",
                                          "image",
                                          "video",
                                          "document"
                                        ],
                                        "type": "string"
                                      },
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "type"
                                    ],
                                    "additionalProperties": {}
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "name": {
                                        "const": "review_and_pay"
                                      },
                                      "parameters": {
                                        "type": "object",
                                        "properties": {
                                          "reference_id": {
                                            "type": "string",
                                            "pattern": "^[A-Za-z0-9_.-]{1,35}$"
                                          },
                                          "type": {
                                            "enum": [
                                              "digital-goods",
                                              "physical-goods"
                                            ],
                                            "type": "string"
                                          },
                                          "payment_type": {
                                            "type": "string",
                                            "minLength": 1,
                                            "maxLength": 16
                                          },
                                          "payment_settings": {
                                            "type": "array",
                                            "minItems": 1,
                                            "maxItems": 3,
                                            "items": {
                                              "anyOf": [
                                                {
                                                  "type": "object",
                                                  "properties": {
                                                    "type": {
                                                      "const": "pix_dynamic_code"
                                                    },
                                                    "pix_dynamic_code": {
                                                      "type": "object",
                                                      "properties": {
                                                        "code": {},
                                                        "merchant_name": {},
                                                        "key": {},
                                                        "key_type": {}
                                                      }
                                                    }
                                                  },
                                                  "required": [
                                                    "type",
                                                    "pix_dynamic_code"
                                                  ]
                                                },
                                                {
                                                  "type": "object",
                                                  "properties": {
                                                    "type": {
                                                      "const": "payment_link"
                                                    },
                                                    "payment_link": {
                                                      "type": "object",
                                                      "properties": {
                                                        "uri": {}
                                                      }
                                                    }
                                                  },
                                                  "required": [
                                                    "type",
                                                    "payment_link"
                                                  ]
                                                },
                                                {
                                                  "type": "object",
                                                  "properties": {
                                                    "type": {
                                                      "const": "boleto"
                                                    },
                                                    "boleto": {
                                                      "type": "object",
                                                      "properties": {
                                                        "digitable_line": {}
                                                      }
                                                    }
                                                  },
                                                  "required": [
                                                    "type",
                                                    "boleto"
                                                  ]
                                                }
                                              ]
                                            }
                                          },
                                          "currency": {
                                            "type": "string",
                                            "minLength": 3,
                                            "maxLength": 3
                                          },
                                          "total_amount": {
                                            "type": "object",
                                            "properties": {
                                              "value": {
                                                "type": "integer",
                                                "minimum": 0,
                                                "maximum": 9007199254740991
                                              },
                                              "offset": {
                                                "const": 100
                                              }
                                            },
                                            "required": [
                                              "value",
                                              "offset"
                                            ]
                                          },
                                          "order": {
                                            "type": "object",
                                            "properties": {
                                              "status": {
                                                "const": "pending"
                                              },
                                              "catalog_id": {
                                                "type": "string",
                                                "minLength": 1,
                                                "maxLength": 128
                                              },
                                              "items": {
                                                "type": "array",
                                                "minItems": 1,
                                                "maxItems": 100,
                                                "items": {
                                                  "type": "object",
                                                  "properties": {
                                                    "retailer_id": {
                                                      "type": "string",
                                                      "minLength": 1,
                                                      "maxLength": 128
                                                    },
                                                    "name": {
                                                      "type": "string",
                                                      "minLength": 1,
                                                      "maxLength": 60
                                                    },
                                                    "amount": {
                                                      "type": "object",
                                                      "properties": {
                                                        "value": {},
                                                        "offset": {}
                                                      }
                                                    },
                                                    "sale_amount": {
                                                      "type": "object",
                                                      "properties": {
                                                        "value": {},
                                                        "offset": {}
                                                      }
                                                    },
                                                    "quantity": {
                                                      "type": "integer",
                                                      "minimum": 1,
                                                      "maximum": 9007199254740991
                                                    }
                                                  },
                                                  "required": [
                                                    "retailer_id",
                                                    "name",
                                                    "amount",
                                                    "quantity"
                                                  ],
                                                  "additionalProperties": {}
                                                }
                                              },
                                              "subtotal": {
                                                "type": "object",
                                                "properties": {
                                                  "value": {
                                                    "type": "integer",
                                                    "minimum": 0,
                                                    "maximum": 9007199254740991
                                                  },
                                                  "offset": {
                                                    "const": 100
                                                  }
                                                },
                                                "required": [
                                                  "value",
                                                  "offset"
                                                ]
                                              },
                                              "tax": {
                                                "type": "object",
                                                "properties": {
                                                  "value": {
                                                    "type": "integer",
                                                    "minimum": 0,
                                                    "maximum": 9007199254740991
                                                  },
                                                  "offset": {
                                                    "const": 100
                                                  },
                                                  "description": {
                                                    "type": "string",
                                                    "maxLength": 60
                                                  }
                                                },
                                                "required": [
                                                  "value",
                                                  "offset"
                                                ]
                                              },
                                              "shipping": {
                                                "type": "object",
                                                "properties": {
                                                  "value": {
                                                    "type": "integer",
                                                    "minimum": 0,
                                                    "maximum": 9007199254740991
                                                  },
                                                  "offset": {
                                                    "const": 100
                                                  },
                                                  "description": {
                                                    "type": "string",
                                                    "maxLength": 60
                                                  }
                                                },
                                                "required": [
                                                  "value",
                                                  "offset"
                                                ]
                                              },
                                              "discount": {
                                                "type": "object",
                                                "properties": {
                                                  "value": {
                                                    "type": "integer",
                                                    "minimum": 0,
                                                    "maximum": 9007199254740991
                                                  },
                                                  "offset": {
                                                    "const": 100
                                                  },
                                                  "description": {
                                                    "type": "string",
                                                    "maxLength": 60
                                                  }
                                                },
                                                "required": [
                                                  "value",
                                                  "offset"
                                                ]
                                              },
                                              "expiration": {
                                                "type": "object",
                                                "properties": {
                                                  "timestamp": {
                                                    "type": "string",
                                                    "minLength": 1,
                                                    "maxLength": 16
                                                  },
                                                  "description": {
                                                    "type": "string",
                                                    "maxLength": 60
                                                  }
                                                },
                                                "required": [
                                                  "timestamp",
                                                  "description"
                                                ]
                                              }
                                            },
                                            "required": [
                                              "status",
                                              "items",
                                              "subtotal",
                                              "tax"
                                            ],
                                            "additionalProperties": {}
                                          }
                                        },
                                        "required": [
                                          "reference_id",
                                          "type",
                                          "payment_type",
                                          "payment_settings",
                                          "currency",
                                          "total_amount",
                                          "order"
                                        ],
                                        "additionalProperties": {}
                                      }
                                    },
                                    "required": [
                                      "name",
                                      "parameters"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "order_status"
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "footer": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "maxLength": 60
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "name": {
                                        "const": "review_order"
                                      },
                                      "parameters": {
                                        "type": "object",
                                        "properties": {
                                          "reference_id": {
                                            "type": "string",
                                            "pattern": "^[A-Za-z0-9_.-]{1,35}$"
                                          },
                                          "order": {
                                            "type": "object",
                                            "properties": {
                                              "status": {
                                                "enum": [
                                                  "pending",
                                                  "processing",
                                                  "partially_shipped",
                                                  "shipped",
                                                  "completed",
                                                  "canceled"
                                                ],
                                                "type": "string"
                                              },
                                              "description": {
                                                "type": "string",
                                                "maxLength": 120
                                              }
                                            },
                                            "required": [
                                              "status"
                                            ],
                                            "additionalProperties": {}
                                          }
                                        },
                                        "required": [
                                          "reference_id",
                                          "order"
                                        ],
                                        "additionalProperties": {}
                                      }
                                    },
                                    "required": [
                                      "name",
                                      "parameters"
                                    ],
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": {}
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "call_permission_request"
                                  },
                                  "body": {
                                    "type": "object",
                                    "properties": {
                                      "text": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 1024
                                      }
                                    },
                                    "required": [
                                      "text"
                                    ]
                                  },
                                  "action": {
                                    "type": "object",
                                    "properties": {
                                      "name": {
                                        "const": "call_permission_request"
                                      }
                                    },
                                    "required": [
                                      "name"
                                    ],
                                    "additionalProperties": false
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "action"
                                ],
                                "additionalProperties": false
                              }
                            ]
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "interactive"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "otp"
                          },
                          "otp": {
                            "type": "object",
                            "properties": {
                              "template_id": {
                                "type": "string",
                                "maxLength": 64,
                                "pattern": "^tpl_.*"
                              },
                              "template": {
                                "type": "object",
                                "properties": {
                                  "name": {
                                    "type": "string",
                                    "minLength": 1,
                                    "maxLength": 512
                                  },
                                  "language": {
                                    "type": "string",
                                    "minLength": 2,
                                    "maxLength": 16
                                  }
                                },
                                "required": [
                                  "name",
                                  "language"
                                ],
                                "additionalProperties": false
                              },
                              "code": {
                                "type": "string",
                                "pattern": "^[A-Za-z0-9]{4,15}$"
                              }
                            },
                            "required": [
                              "code"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "otp"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "reaction"
                          },
                          "reaction": {
                            "type": "object",
                            "properties": {
                              "message_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "emoji": {
                                "type": "string",
                                "maxLength": 16
                              }
                            },
                            "required": [
                              "message_id",
                              "emoji"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "reaction"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "location"
                          },
                          "location": {
                            "type": "object",
                            "properties": {
                              "latitude": {
                                "type": "number",
                                "minimum": -90,
                                "maximum": 90
                              },
                              "longitude": {
                                "type": "number",
                                "minimum": -180,
                                "maximum": 180
                              },
                              "name": {
                                "type": "string",
                                "maxLength": 256
                              },
                              "address": {
                                "type": "string",
                                "maxLength": 512
                              }
                            },
                            "required": [
                              "latitude",
                              "longitude"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "location"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 135
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "biz_opaque_callback_data": {
                            "type": "string",
                            "maxLength": 512
                          },
                          "type": {
                            "const": "contacts"
                          },
                          "contacts": {
                            "type": "array",
                            "minItems": 1,
                            "maxItems": 10,
                            "items": {
                              "type": "object",
                              "properties": {
                                "name": {
                                  "type": "object",
                                  "properties": {
                                    "formatted_name": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 256
                                    },
                                    "first_name": {
                                      "type": "string",
                                      "maxLength": 128
                                    },
                                    "last_name": {
                                      "type": "string",
                                      "maxLength": 128
                                    }
                                  },
                                  "required": [
                                    "formatted_name"
                                  ],
                                  "additionalProperties": false
                                },
                                "phones": {
                                  "type": "array",
                                  "maxItems": 10,
                                  "items": {
                                    "type": "object",
                                    "properties": {
                                      "phone": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 64
                                      },
                                      "type": {
                                        "type": "string",
                                        "maxLength": 32
                                      },
                                      "wa_id": {
                                        "type": "string",
                                        "maxLength": 64
                                      }
                                    },
                                    "required": [
                                      "phone"
                                    ],
                                    "additionalProperties": false
                                  }
                                },
                                "emails": {
                                  "type": "array",
                                  "maxItems": 10,
                                  "items": {
                                    "type": "object",
                                    "properties": {
                                      "email": {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 128
                                      },
                                      "type": {
                                        "type": "string",
                                        "maxLength": 32
                                      }
                                    },
                                    "required": [
                                      "email"
                                    ],
                                    "additionalProperties": false
                                  }
                                }
                              },
                              "required": [
                                "name"
                              ],
                              "additionalProperties": false
                            }
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "contacts"
                        ],
                        "additionalProperties": false
                      }
                    ]
                  },
                  {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "text"
                          },
                          "text": {
                            "type": "object",
                            "properties": {
                              "body": {
                                "type": "string",
                                "minLength": 1
                              },
                              "quick_replies": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 13,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "title": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 20
                                    },
                                    "payload": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 1000
                                    }
                                  },
                                  "required": [
                                    "title",
                                    "payload"
                                  ],
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "body"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "text"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "image"
                          },
                          "image": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "image"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "video"
                          },
                          "video": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "video"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "audio"
                          },
                          "audio": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "audio"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "document"
                          },
                          "document": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "document"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "images"
                          },
                          "images": {
                            "type": "object",
                            "properties": {
                              "items": {
                                "type": "array",
                                "minItems": 2,
                                "maxItems": 10,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "media_id": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 256
                                    },
                                    "link": {
                                      "type": "string",
                                      "format": "uri"
                                    }
                                  },
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "items"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "images"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "like"
                          }
                        },
                        "required": [
                          "to",
                          "type"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "reaction"
                          },
                          "reaction": {
                            "type": "object",
                            "properties": {
                              "message_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "emoji": {
                                "type": "string",
                                "maxLength": 16
                              }
                            },
                            "required": [
                              "message_id",
                              "emoji"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "reaction"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "share"
                          },
                          "share": {
                            "type": "object",
                            "properties": {
                              "post_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 64
                              }
                            },
                            "required": [
                              "post_id"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "share"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "buttons"
                          },
                          "buttons": {
                            "type": "object",
                            "properties": {
                              "text": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 640
                              },
                              "buttons": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 3,
                                "items": {
                                  "anyOf": [
                                    {
                                      "type": "object",
                                      "properties": {
                                        "type": {
                                          "const": "postback"
                                        },
                                        "title": {
                                          "type": "string",
                                          "minLength": 1,
                                          "maxLength": 20
                                        },
                                        "payload": {
                                          "type": "string",
                                          "minLength": 1,
                                          "maxLength": 1000
                                        }
                                      },
                                      "required": [
                                        "type",
                                        "title",
                                        "payload"
                                      ],
                                      "additionalProperties": false
                                    },
                                    {
                                      "type": "object",
                                      "properties": {
                                        "type": {
                                          "const": "web_url"
                                        },
                                        "title": {
                                          "type": "string",
                                          "minLength": 1,
                                          "maxLength": 20
                                        },
                                        "url": {
                                          "type": "string",
                                          "format": "uri"
                                        }
                                      },
                                      "required": [
                                        "type",
                                        "title",
                                        "url"
                                      ],
                                      "additionalProperties": false
                                    }
                                  ]
                                }
                              },
                              "quick_replies": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 13,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "title": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 20
                                    },
                                    "payload": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 1000
                                    }
                                  },
                                  "required": [
                                    "title",
                                    "payload"
                                  ],
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "text",
                              "buttons"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "buttons"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "cards"
                          },
                          "cards": {
                            "type": "object",
                            "properties": {
                              "cards": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 10,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "title": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 80
                                    },
                                    "subtitle": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 80
                                    },
                                    "image_url": {
                                      "type": "string",
                                      "format": "uri"
                                    },
                                    "default_url": {
                                      "type": "string",
                                      "format": "uri"
                                    },
                                    "buttons": {
                                      "type": "array",
                                      "minItems": 1,
                                      "maxItems": 3,
                                      "items": {
                                        "anyOf": [
                                          {
                                            "type": "object",
                                            "properties": {
                                              "type": {
                                                "const": "postback"
                                              },
                                              "title": {
                                                "type": "string",
                                                "minLength": 1,
                                                "maxLength": 20
                                              },
                                              "payload": {
                                                "type": "string",
                                                "minLength": 1,
                                                "maxLength": 1000
                                              }
                                            },
                                            "required": [
                                              "type",
                                              "title",
                                              "payload"
                                            ],
                                            "additionalProperties": false
                                          },
                                          {
                                            "type": "object",
                                            "properties": {
                                              "type": {
                                                "const": "web_url"
                                              },
                                              "title": {
                                                "type": "string",
                                                "minLength": 1,
                                                "maxLength": 20
                                              },
                                              "url": {
                                                "type": "string",
                                                "format": "uri"
                                              }
                                            },
                                            "required": [
                                              "type",
                                              "title",
                                              "url"
                                            ],
                                            "additionalProperties": false
                                          }
                                        ]
                                      }
                                    }
                                  },
                                  "required": [
                                    "title"
                                  ],
                                  "additionalProperties": false
                                }
                              },
                              "quick_replies": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 13,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "title": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 20
                                    },
                                    "payload": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 1000
                                    }
                                  },
                                  "required": [
                                    "title",
                                    "payload"
                                  ],
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "cards"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "cards"
                        ],
                        "additionalProperties": false
                      }
                    ]
                  },
                  {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "text"
                          },
                          "text": {
                            "type": "object",
                            "properties": {
                              "body": {
                                "type": "string",
                                "minLength": 1
                              },
                              "quick_replies": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 13,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "title": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 20
                                    },
                                    "payload": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 1000
                                    }
                                  },
                                  "required": [
                                    "title",
                                    "payload"
                                  ],
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "body"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "text"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "image"
                          },
                          "image": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "image"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "video"
                          },
                          "video": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "video"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "audio"
                          },
                          "audio": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "audio"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "document"
                          },
                          "document": {
                            "type": "object",
                            "properties": {
                              "media_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "link": {
                                "type": "string",
                                "format": "uri"
                              }
                            },
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "document"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "images"
                          },
                          "images": {
                            "type": "object",
                            "properties": {
                              "items": {
                                "type": "array",
                                "minItems": 2,
                                "maxItems": 1,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "media_id": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 256
                                    },
                                    "link": {
                                      "type": "string",
                                      "format": "uri"
                                    }
                                  },
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "items"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "images"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "like"
                          }
                        },
                        "required": [
                          "to",
                          "type"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "reaction"
                          },
                          "reaction": {
                            "type": "object",
                            "properties": {
                              "message_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              },
                              "emoji": {
                                "type": "string",
                                "maxLength": 16
                              }
                            },
                            "required": [
                              "message_id",
                              "emoji"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "reaction"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "share"
                          },
                          "share": {
                            "type": "object",
                            "properties": {
                              "post_id": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 64
                              }
                            },
                            "required": [
                              "post_id"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "share"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "buttons"
                          },
                          "buttons": {
                            "type": "object",
                            "properties": {
                              "text": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 640
                              },
                              "buttons": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 3,
                                "items": {
                                  "anyOf": [
                                    {
                                      "type": "object",
                                      "properties": {
                                        "type": {
                                          "const": "postback"
                                        },
                                        "title": {
                                          "type": "string",
                                          "minLength": 1,
                                          "maxLength": 20
                                        },
                                        "payload": {
                                          "type": "string",
                                          "minLength": 1,
                                          "maxLength": 1000
                                        }
                                      },
                                      "required": [
                                        "type",
                                        "title",
                                        "payload"
                                      ],
                                      "additionalProperties": false
                                    },
                                    {
                                      "type": "object",
                                      "properties": {
                                        "type": {
                                          "const": "web_url"
                                        },
                                        "title": {
                                          "type": "string",
                                          "minLength": 1,
                                          "maxLength": 20
                                        },
                                        "url": {
                                          "type": "string",
                                          "format": "uri"
                                        }
                                      },
                                      "required": [
                                        "type",
                                        "title",
                                        "url"
                                      ],
                                      "additionalProperties": false
                                    }
                                  ]
                                }
                              },
                              "quick_replies": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 13,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "title": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 20
                                    },
                                    "payload": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 1000
                                    }
                                  },
                                  "required": [
                                    "title",
                                    "payload"
                                  ],
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "text",
                              "buttons"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "buttons"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "connection_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 64
                          },
                          "reply_to": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 256
                          },
                          "tag": {
                            "const": "human_agent"
                          },
                          "delay_ms": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 20000,
                            "default": 0
                          },
                          "typing": {
                            "type": "boolean",
                            "default": false
                          },
                          "type": {
                            "const": "cards"
                          },
                          "cards": {
                            "type": "object",
                            "properties": {
                              "cards": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 10,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "title": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 80
                                    },
                                    "subtitle": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 80
                                    },
                                    "image_url": {
                                      "type": "string",
                                      "format": "uri"
                                    },
                                    "default_url": {
                                      "type": "string",
                                      "format": "uri"
                                    },
                                    "buttons": {
                                      "type": "array",
                                      "minItems": 1,
                                      "maxItems": 3,
                                      "items": {
                                        "anyOf": [
                                          {
                                            "type": "object",
                                            "properties": {
                                              "type": {
                                                "const": "postback"
                                              },
                                              "title": {
                                                "type": "string",
                                                "minLength": 1,
                                                "maxLength": 20
                                              },
                                              "payload": {
                                                "type": "string",
                                                "minLength": 1,
                                                "maxLength": 1000
                                              }
                                            },
                                            "required": [
                                              "type",
                                              "title",
                                              "payload"
                                            ],
                                            "additionalProperties": false
                                          },
                                          {
                                            "type": "object",
                                            "properties": {
                                              "type": {
                                                "const": "web_url"
                                              },
                                              "title": {
                                                "type": "string",
                                                "minLength": 1,
                                                "maxLength": 20
                                              },
                                              "url": {
                                                "type": "string",
                                                "format": "uri"
                                              }
                                            },
                                            "required": [
                                              "type",
                                              "title",
                                              "url"
                                            ],
                                            "additionalProperties": false
                                          }
                                        ]
                                      }
                                    }
                                  },
                                  "required": [
                                    "title"
                                  ],
                                  "additionalProperties": false
                                }
                              },
                              "quick_replies": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 13,
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "title": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 20
                                    },
                                    "payload": {
                                      "type": "string",
                                      "minLength": 1,
                                      "maxLength": 1000
                                    }
                                  },
                                  "required": [
                                    "title",
                                    "payload"
                                  ],
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "cards"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "to",
                          "type",
                          "cards"
                        ],
                        "additionalProperties": false
                      }
                    ]
                  }
                ],
                "description": "Mensagem a enviar, no formato do `type` escolhido e do canal da conexão."
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A mensagem gravada e aceita pela Meta.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da mensagem no Messajo (`msg_…`).",
                      "examples": [
                        "msg_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID da mensagem na Meta (`wamid`)."
                    },
                    "status": {
                      "const": "queued",
                      "description": "Status da mensagem; começa em `queued` e muda pelos webhooks."
                    },
                    "meta_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Resposta da Meta: `accepted`, `held_for_quality_assessment`, `paused` ou `null`."
                    },
                    "conversation_id": {
                      "type": "string",
                      "description": "Conversa da mensagem."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contato destinatário."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a mensagem foi gravada (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "status",
                    "meta_status",
                    "conversation_id",
                    "contact_id",
                    "created_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      },
      "get": {
        "operationId": "listMessages",
        "summary": "Listar mensagens",
        "description": "Lista as mensagens da organização com filtros. O intervalo `since`…`until` fica sempre dentro da retenção: pedido maior é cortado, sem erro. Permissão: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "Cursor opaco da página seguinte: o `next_cursor` da resposta anterior, com os mesmos filtros. Adulterado ou de outra rota → `400 invalid_cursor`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "order",
            "in": "query",
            "schema": {
              "enum": [
                "desc",
                "asc"
              ],
              "type": "string",
              "default": "desc",
              "description": "Ordem: `desc` (padrão, mais nova primeiro) ou `asc`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "enum": [
                "inbound",
                "outbound"
              ],
              "type": "string",
              "description": "Direção: `inbound` (recebida) ou `outbound` (enviada)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Tipo do conteúdo, ex.: `text`, `image`, `template`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Início do intervalo (ISO 8601). Padrão e limite: agora menos a retenção da organização."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fim do intervalo (ISO 8601). Padrão: agora."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "contact_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do contato."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "conversation_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conversa."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "received",
                "queued",
                "sent",
                "delivered",
                "read",
                "played",
                "failed",
                "deleted"
              ],
              "type": "string",
              "description": "Status da mensagem."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "enum": [
                "customer",
                "api",
                "business_app",
                "history",
                "campaign"
              ],
              "type": "string",
              "description": "Origem: `customer`, `api`, `business_app`, `history` ou `campaign`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "campaign_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Só mensagens desta campanha."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de mensagens.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da mensagem no Messajo (`msg_…`).",
                            "examples": [
                              "msg_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID da mensagem na Meta; `null` antes do aceite."
                          },
                          "direction": {
                            "enum": [
                              "inbound",
                              "outbound"
                            ],
                            "type": "string",
                            "description": "Direção: `inbound` (recebida) ou `outbound` (enviada)."
                          },
                          "source": {
                            "enum": [
                              "customer",
                              "api",
                              "business_app",
                              "history",
                              "campaign"
                            ],
                            "type": "string",
                            "description": "Origem: `customer`, `api`, `business_app`, `history` ou `campaign`."
                          },
                          "timestamp": {
                            "type": "string",
                            "description": "Quando a mensagem aconteceu (ISO 8601, UTC)."
                          },
                          "content": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "text"
                                  },
                                  "body": {
                                    "type": "string"
                                  },
                                  "quick_replies": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "title": {
                                          "type": "string"
                                        },
                                        "payload": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "title",
                                        "payload"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "body"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "enum": [
                                      "image",
                                      "video",
                                      "document"
                                    ]
                                  },
                                  "media": {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "mime_type": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "sha256": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "size_bytes": {
                                        "anyOf": [
                                          {
                                            "type": "integer",
                                            "minimum": 0,
                                            "maximum": 9007199254740991
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "filename": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "caption": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "status": {
                                        "enum": [
                                          "pending",
                                          "stored",
                                          "failed"
                                        ],
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "id",
                                      "mime_type",
                                      "sha256",
                                      "size_bytes",
                                      "filename",
                                      "caption",
                                      "status"
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "media"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "audio"
                                  },
                                  "media": {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "mime_type": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "sha256": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "size_bytes": {
                                        "anyOf": [
                                          {
                                            "type": "integer",
                                            "minimum": 0,
                                            "maximum": 9007199254740991
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "filename": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "caption": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "status": {
                                        "enum": [
                                          "pending",
                                          "stored",
                                          "failed"
                                        ],
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "id",
                                      "mime_type",
                                      "sha256",
                                      "size_bytes",
                                      "filename",
                                      "caption",
                                      "status"
                                    ]
                                  },
                                  "voice": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "type",
                                  "media",
                                  "voice"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "images"
                                  },
                                  "images": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "id": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "mime_type": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "sha256": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "size_bytes": {
                                          "anyOf": [
                                            {
                                              "type": "integer",
                                              "minimum": 0,
                                              "maximum": 9007199254740991
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "filename": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "caption": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "status": {
                                          "enum": [
                                            "pending",
                                            "stored",
                                            "failed"
                                          ],
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "id",
                                        "mime_type",
                                        "sha256",
                                        "size_bytes",
                                        "filename",
                                        "caption",
                                        "status"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "images"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "like"
                                  }
                                },
                                "required": [
                                  "type"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "sticker"
                                  },
                                  "media": {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "mime_type": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "sha256": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "size_bytes": {
                                        "anyOf": [
                                          {
                                            "type": "integer",
                                            "minimum": 0,
                                            "maximum": 9007199254740991
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "filename": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "caption": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "status": {
                                        "enum": [
                                          "pending",
                                          "stored",
                                          "failed"
                                        ],
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "id",
                                      "mime_type",
                                      "sha256",
                                      "size_bytes",
                                      "filename",
                                      "caption",
                                      "status"
                                    ]
                                  },
                                  "animated": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "type",
                                  "media",
                                  "animated"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "location"
                                  },
                                  "latitude": {
                                    "type": "number"
                                  },
                                  "longitude": {
                                    "type": "number"
                                  },
                                  "name": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "address": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "url": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "latitude",
                                  "longitude",
                                  "name",
                                  "address",
                                  "url"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "contacts"
                                  },
                                  "contacts": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "name": {
                                          "type": "object",
                                          "properties": {
                                            "formatted_name": {
                                              "type": "string"
                                            },
                                            "first_name": {
                                              "anyOf": [
                                                {
                                                  "type": "string"
                                                },
                                                {
                                                  "type": "null"
                                                }
                                              ]
                                            },
                                            "last_name": {
                                              "anyOf": [
                                                {
                                                  "type": "string"
                                                },
                                                {
                                                  "type": "null"
                                                }
                                              ]
                                            }
                                          },
                                          "required": [
                                            "formatted_name",
                                            "first_name",
                                            "last_name"
                                          ]
                                        },
                                        "phones": {
                                          "type": "array",
                                          "items": {
                                            "type": "object",
                                            "properties": {
                                              "phone": {
                                                "type": "string"
                                              },
                                              "wa_id": {
                                                "anyOf": [
                                                  {
                                                    "type": "string"
                                                  },
                                                  {
                                                    "type": "null"
                                                  }
                                                ]
                                              },
                                              "type": {
                                                "anyOf": [
                                                  {
                                                    "type": "string"
                                                  },
                                                  {
                                                    "type": "null"
                                                  }
                                                ]
                                              }
                                            },
                                            "required": [
                                              "phone",
                                              "wa_id",
                                              "type"
                                            ]
                                          }
                                        },
                                        "emails": {
                                          "type": "array",
                                          "items": {
                                            "type": "object",
                                            "properties": {
                                              "email": {
                                                "type": "string"
                                              },
                                              "type": {
                                                "anyOf": [
                                                  {
                                                    "type": "string"
                                                  },
                                                  {
                                                    "type": "null"
                                                  }
                                                ]
                                              }
                                            },
                                            "required": [
                                              "email",
                                              "type"
                                            ]
                                          }
                                        }
                                      },
                                      "required": [
                                        "name",
                                        "phones",
                                        "emails"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "contacts"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "reaction"
                                  },
                                  "message_id": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "external_message_id": {
                                    "type": "string"
                                  },
                                  "emoji": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "message_id",
                                  "external_message_id",
                                  "emoji"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "reply"
                                  },
                                  "kind": {
                                    "enum": [
                                      "button",
                                      "list",
                                      "quick_reply",
                                      "postback",
                                      "flow"
                                    ],
                                    "type": "string"
                                  },
                                  "id": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "title": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "description": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "payload": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "kind",
                                  "id",
                                  "title",
                                  "description",
                                  "payload"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "order"
                                  },
                                  "catalog_id": {
                                    "type": "string"
                                  },
                                  "items": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "product_retailer_id": {
                                          "type": "string"
                                        },
                                        "quantity": {
                                          "type": "integer",
                                          "minimum": -9007199254740991,
                                          "maximum": 9007199254740991,
                                          "exclusiveMinimum": 0
                                        },
                                        "item_price": {
                                          "type": "number",
                                          "minimum": 0
                                        },
                                        "currency": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "product_retailer_id",
                                        "quantity",
                                        "item_price",
                                        "currency"
                                      ]
                                    }
                                  },
                                  "note": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "catalog_id",
                                  "items",
                                  "note"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "call_permission_reply"
                                  },
                                  "response": {
                                    "enum": [
                                      "accept",
                                      "reject"
                                    ],
                                    "type": "string"
                                  },
                                  "permanent": {
                                    "type": "boolean"
                                  },
                                  "expires_at": {
                                    "anyOf": [
                                      {
                                        "type": "string",
                                        "format": "date-time"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "source": {
                                    "enum": [
                                      "user_action",
                                      "automatic"
                                    ],
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "type",
                                  "response",
                                  "permanent",
                                  "expires_at",
                                  "source"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "share"
                                  },
                                  "kind": {
                                    "enum": [
                                      "post",
                                      "reel",
                                      "story",
                                      "story_mention",
                                      "link"
                                    ],
                                    "type": "string"
                                  },
                                  "url": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "external_id": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "kind",
                                  "url",
                                  "external_id"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "system"
                                  },
                                  "kind": {
                                    "type": "string"
                                  },
                                  "body": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "kind",
                                  "body"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "unsupported"
                                  },
                                  "meta_type": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "type",
                                  "meta_type"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "template"
                                  },
                                  "name": {
                                    "type": "string"
                                  },
                                  "language": {
                                    "type": "string"
                                  },
                                  "components": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "propertyNames": {
                                        "type": "string"
                                      },
                                      "additionalProperties": {}
                                    }
                                  },
                                  "otp": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "type",
                                  "name",
                                  "language",
                                  "components"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "interactive"
                                  },
                                  "kind": {
                                    "enum": [
                                      "button",
                                      "list",
                                      "cta_url",
                                      "location_request",
                                      "flow",
                                      "product",
                                      "product_list",
                                      "catalog_message",
                                      "order_details",
                                      "order_status",
                                      "call_permission_request"
                                    ],
                                    "type": "string"
                                  },
                                  "body": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "interactive": {
                                    "type": "object",
                                    "propertyNames": {
                                      "type": "string"
                                    },
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "kind",
                                  "body",
                                  "interactive"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "buttons"
                                  },
                                  "body": {
                                    "type": "string"
                                  },
                                  "buttons": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                      "anyOf": [
                                        {
                                          "type": "object",
                                          "properties": {
                                            "type": {
                                              "const": "postback"
                                            },
                                            "title": {
                                              "type": "string"
                                            },
                                            "payload": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "type",
                                            "title",
                                            "payload"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "type": {
                                              "const": "web_url"
                                            },
                                            "title": {
                                              "type": "string"
                                            },
                                            "url": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "type",
                                            "title",
                                            "url"
                                          ]
                                        }
                                      ]
                                    }
                                  },
                                  "quick_replies": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "title": {
                                          "type": "string"
                                        },
                                        "payload": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "title",
                                        "payload"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "buttons"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "cards"
                                  },
                                  "cards": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "title": {
                                          "type": "string"
                                        },
                                        "subtitle": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "image_url": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "default_url": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "buttons": {
                                          "type": "array",
                                          "items": {
                                            "anyOf": [
                                              {
                                                "type": "object",
                                                "properties": {
                                                  "type": {
                                                    "const": "postback"
                                                  },
                                                  "title": {
                                                    "type": "string"
                                                  },
                                                  "payload": {
                                                    "type": "string"
                                                  }
                                                },
                                                "required": [
                                                  "type",
                                                  "title",
                                                  "payload"
                                                ]
                                              },
                                              {
                                                "type": "object",
                                                "properties": {
                                                  "type": {
                                                    "const": "web_url"
                                                  },
                                                  "title": {
                                                    "type": "string"
                                                  },
                                                  "url": {
                                                    "type": "string"
                                                  }
                                                },
                                                "required": [
                                                  "type",
                                                  "title",
                                                  "url"
                                                ]
                                              }
                                            ]
                                          }
                                        }
                                      },
                                      "required": [
                                        "title",
                                        "subtitle",
                                        "image_url",
                                        "default_url",
                                        "buttons"
                                      ]
                                    }
                                  },
                                  "quick_replies": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "title": {
                                          "type": "string"
                                        },
                                        "payload": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "title",
                                        "payload"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "cards"
                                ]
                              }
                            ],
                            "description": "Conteúdo normalizado (o mesmo dos eventos `message.*`)."
                          },
                          "context": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "reply_to": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "message_id": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "external_id": {
                                            "type": "string"
                                          }
                                        },
                                        "required": [
                                          "message_id",
                                          "external_id"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "forwarded": {
                                    "type": "boolean"
                                  },
                                  "frequently_forwarded": {
                                    "type": "boolean"
                                  },
                                  "referral": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "source_type": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "source_id": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "source_url": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "headline": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "ctwa_clid": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          }
                                        },
                                        "required": [
                                          "source_type",
                                          "source_id",
                                          "source_url",
                                          "headline",
                                          "ctwa_clid"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "reply_to_story": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "external_id": {
                                            "type": "string"
                                          },
                                          "url": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          }
                                        },
                                        "required": [
                                          "external_id",
                                          "url"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "standby": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "reply_to",
                                  "forwarded",
                                  "frequently_forwarded",
                                  "referral"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Contexto: resposta, encaminhamento, anúncio de origem; `null` = sem contexto."
                          },
                          "conversation_id": {
                            "type": "string",
                            "description": "ID da conversa."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID do contato."
                          },
                          "status": {
                            "enum": [
                              "received",
                              "queued",
                              "sent",
                              "delivered",
                              "read",
                              "played",
                              "failed",
                              "deleted"
                            ],
                            "type": "string",
                            "description": "Status da mensagem."
                          },
                          "sent_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Enviada (ISO 8601, UTC)."
                          },
                          "delivered_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Entregue (ISO 8601, UTC)."
                          },
                          "read_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Lida (ISO 8601, UTC)."
                          },
                          "failed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Falhou (ISO 8601, UTC)."
                          },
                          "edited_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Editada (ISO 8601, UTC)."
                          },
                          "revoked_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Apagada pelo remetente (ISO 8601, UTC)."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Erro do envio, no formato da Meta; `null` = sem erro."
                          },
                          "campaign": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "description": "Só mensagens desta campanha."
                                  },
                                  "recipient_id": {
                                    "type": "string",
                                    "description": "ID do destinatário da campanha."
                                  }
                                },
                                "required": [
                                  "id",
                                  "recipient_id"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Campanha que enviou a mensagem; `null` fora de campanha."
                          }
                        },
                        "required": [
                          "id",
                          "external_id",
                          "direction",
                          "source",
                          "timestamp",
                          "content",
                          "context",
                          "conversation_id",
                          "contact_id",
                          "status",
                          "sent_at",
                          "delivered_at",
                          "read_at",
                          "failed_at",
                          "edited_at",
                          "revoked_at",
                          "error",
                          "campaign"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/messages/{id}/read": {
      "post": {
        "operationId": "markMessageRead",
        "summary": "Marcar como lida",
        "description": "Marca uma mensagem recebida como lida. Com `typing: true` também mostra \"digitando…\" ao contato; no WhatsApp o \"digitando\" sempre marca como lida. Permissão: `send`.",
        "tags": [
          "messages"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Mensagem recebida (`msg_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "typing": {
                    "type": "boolean",
                    "default": false,
                    "description": "Também mostrar \"digitando…\"."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Confirmação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Mensagem recebida (`msg_…`)."
                    },
                    "read": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "read"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/templates": {
      "get": {
        "operationId": "listTemplates",
        "summary": "Listar templates",
        "description": "Lista os templates das contas do WhatsApp da organização, com filtros. Chave presa a conexões precisa informar `connection_id`. Permissão: `read`.",
        "tags": [
          "templates"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Conexão cuja conta do WhatsApp é usada. Opcional com chave de conexão (usa a conexão da chave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "APPROVED",
                "PENDING",
                "REJECTED",
                "PAUSED",
                "DISABLED",
                "IN_APPEAL",
                "PENDING_DELETION",
                "DELETED",
                "ARCHIVED",
                "LIMIT_EXCEEDED",
                "LOCKED",
                "FLAGGED",
                "REINSTATED"
              ],
              "type": "string",
              "description": "Status na Meta, ex.: `APPROVED`, `PENDING`, `REJECTED`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "enum": [
                "MARKETING",
                "UTILITY",
                "AUTHENTICATION"
              ],
              "type": "string",
              "description": "Categoria: `MARKETING`, `UTILITY` ou `AUTHENTICATION`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "language",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Idioma, ex.: `pt_BR`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "name",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Nome (minúsculas, números e `_`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de templates.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do template no Messajo (`tpl_…`).",
                            "examples": [
                              "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "messaging_account_id": {
                            "type": "string",
                            "description": "Conta do WhatsApp Business (WABA) do template."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID do template na Meta."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nome (minúsculas, números e `_`)."
                          },
                          "language": {
                            "type": "string",
                            "description": "Idioma, ex.: `pt_BR`."
                          },
                          "category": {
                            "enum": [
                              "MARKETING",
                              "UTILITY",
                              "AUTHENTICATION"
                            ],
                            "type": "string",
                            "description": "Categoria: `MARKETING`, `UTILITY` ou `AUTHENTICATION`."
                          },
                          "previous_category": {
                            "anyOf": [
                              {
                                "enum": [
                                  "MARKETING",
                                  "UTILITY",
                                  "AUTHENTICATION"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Categoria anterior, quando a Meta reclassificou."
                          },
                          "status": {
                            "enum": [
                              "APPROVED",
                              "PENDING",
                              "REJECTED",
                              "PAUSED",
                              "DISABLED",
                              "IN_APPEAL",
                              "PENDING_DELETION",
                              "DELETED",
                              "ARCHIVED",
                              "LIMIT_EXCEEDED",
                              "LOCKED",
                              "FLAGGED",
                              "REINSTATED"
                            ],
                            "type": "string",
                            "description": "Status na Meta, ex.: `APPROVED`, `PENDING`, `REJECTED`."
                          },
                          "rejected_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo da rejeição, quando há."
                          },
                          "quality_score": {
                            "enum": [
                              "GREEN",
                              "YELLOW",
                              "RED",
                              "UNKNOWN"
                            ],
                            "type": "string",
                            "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                          },
                          "parameter_format": {
                            "enum": [
                              "POSITIONAL",
                              "NAMED"
                            ],
                            "type": "string",
                            "description": "Formato das variáveis: `POSITIONAL` ou `NAMED`."
                          },
                          "components": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            "description": "Componentes no formato da Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                          },
                          "last_synced_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última leitura na Meta (ISO 8601, UTC)."
                          },
                          "status_updated_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última mudança de status (ISO 8601, UTC)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando foi criado no Messajo (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última alteração (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "messaging_account_id",
                          "external_id",
                          "name",
                          "language",
                          "category",
                          "previous_category",
                          "status",
                          "rejected_reason",
                          "quality_score",
                          "parameter_format",
                          "components",
                          "last_synced_at",
                          "status_updated_at",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createTemplate",
        "summary": "Criar template",
        "description": "Cria o template na conta do WhatsApp da conexão e o envia para revisão da Meta; o status muda pelo evento `template.status`. Permissão: `templates`.",
        "tags": [
          "templates"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexão cuja conta do WhatsApp é usada. Opcional com chave de conexão (usa a conexão da chave)."
                  },
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z0-9_]{1,512}$",
                    "description": "Nome (minúsculas, números e `_`)."
                  },
                  "language": {
                    "type": "string",
                    "pattern": "^[a-z]{2,3}(_[A-Z]{2})?$",
                    "description": "Idioma, ex.: `pt_BR`."
                  },
                  "category": {
                    "enum": [
                      "MARKETING",
                      "UTILITY",
                      "AUTHENTICATION"
                    ],
                    "type": "string",
                    "description": "Categoria: `MARKETING`, `UTILITY` ou `AUTHENTICATION`."
                  },
                  "components": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "enum": [
                            "HEADER",
                            "BODY",
                            "FOOTER",
                            "BUTTONS"
                          ],
                          "type": "string"
                        },
                        "format": {
                          "enum": [
                            "TEXT",
                            "IMAGE",
                            "VIDEO",
                            "DOCUMENT",
                            "LOCATION"
                          ],
                          "type": "string"
                        },
                        "text": {
                          "type": "string",
                          "minLength": 1
                        },
                        "buttons": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "type": {
                                "enum": [
                                  "QUICK_REPLY",
                                  "URL",
                                  "PHONE_NUMBER",
                                  "COPY_CODE",
                                  "OTP",
                                  "FLOW",
                                  "CATALOG",
                                  "MPM",
                                  "VOICE_CALL"
                                ],
                                "type": "string"
                              }
                            },
                            "required": [
                              "type"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        "example": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        }
                      },
                      "required": [
                        "type"
                      ],
                      "additionalProperties": {}
                    },
                    "description": "Componentes no formato da Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                  },
                  "parameter_format": {
                    "enum": [
                      "POSITIONAL",
                      "NAMED"
                    ],
                    "type": "string",
                    "description": "Formato das variáveis: `POSITIONAL` ou `NAMED`."
                  }
                },
                "required": [
                  "name",
                  "language",
                  "category",
                  "components"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O template criado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do template no Messajo (`tpl_…`).",
                      "examples": [
                        "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Conta do WhatsApp Business (WABA) do template."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do template na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome (minúsculas, números e `_`)."
                    },
                    "language": {
                      "type": "string",
                      "description": "Idioma, ex.: `pt_BR`."
                    },
                    "category": {
                      "enum": [
                        "MARKETING",
                        "UTILITY",
                        "AUTHENTICATION"
                      ],
                      "type": "string",
                      "description": "Categoria: `MARKETING`, `UTILITY` ou `AUTHENTICATION`."
                    },
                    "previous_category": {
                      "anyOf": [
                        {
                          "enum": [
                            "MARKETING",
                            "UTILITY",
                            "AUTHENTICATION"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Categoria anterior, quando a Meta reclassificou."
                    },
                    "status": {
                      "enum": [
                        "APPROVED",
                        "PENDING",
                        "REJECTED",
                        "PAUSED",
                        "DISABLED",
                        "IN_APPEAL",
                        "PENDING_DELETION",
                        "DELETED",
                        "ARCHIVED",
                        "LIMIT_EXCEEDED",
                        "LOCKED",
                        "FLAGGED",
                        "REINSTATED"
                      ],
                      "type": "string",
                      "description": "Status na Meta, ex.: `APPROVED`, `PENDING`, `REJECTED`."
                    },
                    "rejected_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da rejeição, quando há."
                    },
                    "quality_score": {
                      "enum": [
                        "GREEN",
                        "YELLOW",
                        "RED",
                        "UNKNOWN"
                      ],
                      "type": "string",
                      "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                    },
                    "parameter_format": {
                      "enum": [
                        "POSITIONAL",
                        "NAMED"
                      ],
                      "type": "string",
                      "description": "Formato das variáveis: `POSITIONAL` ou `NAMED`."
                    },
                    "components": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      },
                      "description": "Componentes no formato da Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                    },
                    "last_synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última leitura na Meta (ISO 8601, UTC)."
                    },
                    "status_updated_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última mudança de status (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado no Messajo (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "language",
                    "category",
                    "previous_category",
                    "status",
                    "rejected_reason",
                    "quality_score",
                    "parameter_format",
                    "components",
                    "last_synced_at",
                    "status_updated_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/templates/{id}": {
      "get": {
        "operationId": "getTemplate",
        "summary": "Obter um template",
        "description": "Devolve o template com status, categoria e componentes. Permissão: `read`.",
        "tags": [
          "templates"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do template no Messajo (`tpl_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O template.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do template no Messajo (`tpl_…`).",
                      "examples": [
                        "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Conta do WhatsApp Business (WABA) do template."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do template na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome (minúsculas, números e `_`)."
                    },
                    "language": {
                      "type": "string",
                      "description": "Idioma, ex.: `pt_BR`."
                    },
                    "category": {
                      "enum": [
                        "MARKETING",
                        "UTILITY",
                        "AUTHENTICATION"
                      ],
                      "type": "string",
                      "description": "Categoria: `MARKETING`, `UTILITY` ou `AUTHENTICATION`."
                    },
                    "previous_category": {
                      "anyOf": [
                        {
                          "enum": [
                            "MARKETING",
                            "UTILITY",
                            "AUTHENTICATION"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Categoria anterior, quando a Meta reclassificou."
                    },
                    "status": {
                      "enum": [
                        "APPROVED",
                        "PENDING",
                        "REJECTED",
                        "PAUSED",
                        "DISABLED",
                        "IN_APPEAL",
                        "PENDING_DELETION",
                        "DELETED",
                        "ARCHIVED",
                        "LIMIT_EXCEEDED",
                        "LOCKED",
                        "FLAGGED",
                        "REINSTATED"
                      ],
                      "type": "string",
                      "description": "Status na Meta, ex.: `APPROVED`, `PENDING`, `REJECTED`."
                    },
                    "rejected_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da rejeição, quando há."
                    },
                    "quality_score": {
                      "enum": [
                        "GREEN",
                        "YELLOW",
                        "RED",
                        "UNKNOWN"
                      ],
                      "type": "string",
                      "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                    },
                    "parameter_format": {
                      "enum": [
                        "POSITIONAL",
                        "NAMED"
                      ],
                      "type": "string",
                      "description": "Formato das variáveis: `POSITIONAL` ou `NAMED`."
                    },
                    "components": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      },
                      "description": "Componentes no formato da Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                    },
                    "last_synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última leitura na Meta (ISO 8601, UTC)."
                    },
                    "status_updated_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última mudança de status (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado no Messajo (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "language",
                    "category",
                    "previous_category",
                    "status",
                    "rejected_reason",
                    "quality_score",
                    "parameter_format",
                    "components",
                    "last_synced_at",
                    "status_updated_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateTemplate",
        "summary": "Editar template",
        "description": "Edita os componentes ou a categoria. A Meta só deixa editar templates `APPROVED`, `REJECTED` ou `PAUSED`, e um aprovado não troca de categoria. Permissão: `templates`.",
        "tags": [
          "templates"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do template no Messajo (`tpl_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "category": {
                    "enum": [
                      "MARKETING",
                      "UTILITY",
                      "AUTHENTICATION"
                    ],
                    "type": "string",
                    "description": "Categoria: `MARKETING`, `UTILITY` ou `AUTHENTICATION`."
                  },
                  "components": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "enum": [
                            "HEADER",
                            "BODY",
                            "FOOTER",
                            "BUTTONS"
                          ],
                          "type": "string"
                        },
                        "format": {
                          "enum": [
                            "TEXT",
                            "IMAGE",
                            "VIDEO",
                            "DOCUMENT",
                            "LOCATION"
                          ],
                          "type": "string"
                        },
                        "text": {
                          "type": "string",
                          "minLength": 1
                        },
                        "buttons": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "type": {
                                "enum": [
                                  "QUICK_REPLY",
                                  "URL",
                                  "PHONE_NUMBER",
                                  "COPY_CODE",
                                  "OTP",
                                  "FLOW",
                                  "CATALOG",
                                  "MPM",
                                  "VOICE_CALL"
                                ],
                                "type": "string"
                              }
                            },
                            "required": [
                              "type"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        "example": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        }
                      },
                      "required": [
                        "type"
                      ],
                      "additionalProperties": {}
                    },
                    "description": "Componentes no formato da Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O template atualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do template no Messajo (`tpl_…`).",
                      "examples": [
                        "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Conta do WhatsApp Business (WABA) do template."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do template na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome (minúsculas, números e `_`)."
                    },
                    "language": {
                      "type": "string",
                      "description": "Idioma, ex.: `pt_BR`."
                    },
                    "category": {
                      "enum": [
                        "MARKETING",
                        "UTILITY",
                        "AUTHENTICATION"
                      ],
                      "type": "string",
                      "description": "Categoria: `MARKETING`, `UTILITY` ou `AUTHENTICATION`."
                    },
                    "previous_category": {
                      "anyOf": [
                        {
                          "enum": [
                            "MARKETING",
                            "UTILITY",
                            "AUTHENTICATION"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Categoria anterior, quando a Meta reclassificou."
                    },
                    "status": {
                      "enum": [
                        "APPROVED",
                        "PENDING",
                        "REJECTED",
                        "PAUSED",
                        "DISABLED",
                        "IN_APPEAL",
                        "PENDING_DELETION",
                        "DELETED",
                        "ARCHIVED",
                        "LIMIT_EXCEEDED",
                        "LOCKED",
                        "FLAGGED",
                        "REINSTATED"
                      ],
                      "type": "string",
                      "description": "Status na Meta, ex.: `APPROVED`, `PENDING`, `REJECTED`."
                    },
                    "rejected_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da rejeição, quando há."
                    },
                    "quality_score": {
                      "enum": [
                        "GREEN",
                        "YELLOW",
                        "RED",
                        "UNKNOWN"
                      ],
                      "type": "string",
                      "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                    },
                    "parameter_format": {
                      "enum": [
                        "POSITIONAL",
                        "NAMED"
                      ],
                      "type": "string",
                      "description": "Formato das variáveis: `POSITIONAL` ou `NAMED`."
                    },
                    "components": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      },
                      "description": "Componentes no formato da Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                    },
                    "last_synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última leitura na Meta (ISO 8601, UTC)."
                    },
                    "status_updated_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última mudança de status (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado no Messajo (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "language",
                    "category",
                    "previous_category",
                    "status",
                    "rejected_reason",
                    "quality_score",
                    "parameter_format",
                    "components",
                    "last_synced_at",
                    "status_updated_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteTemplate",
        "summary": "Excluir template",
        "description": "Exclui o template na Meta e no Messajo. Permissão: `templates`.",
        "tags": [
          "templates"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do template no Messajo (`tpl_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmação da exclusão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do template no Messajo (`tpl_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/templates/sync": {
      "post": {
        "operationId": "syncTemplates",
        "summary": "Sincronizar templates",
        "description": "Lê agora na Meta todos os templates da conta da conexão (o Messajo já faz isso todo dia). Template que sumiu da Meta é marcado como excluído. Permissão: `templates`.",
        "tags": [
          "templates"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexão cuja conta do WhatsApp é usada. Opcional com chave de conexão (usa a conexão da chave)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Quantos templates vieram e quantos saíram.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "synced": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Templates lidos da Meta."
                    },
                    "deleted": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Templates marcados como excluídos."
                    }
                  },
                  "required": [
                    "synced",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/media": {
      "post": {
        "operationId": "uploadMedia",
        "summary": "Enviar mídia",
        "description": "Guarda um arquivo (`multipart/form-data`) para usar depois em `POST /messages` (`media_id`) ou como foto do perfil. O tipo é lido dos bytes e precisa caber no limite da Meta. `convert=voice` converte áudio para OGG/Opus (mensagem de voz) e devolve a mídia convertida. Permissão: `send`.",
        "tags": [
          "media"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "O arquivo."
                  },
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexão da mídia. Opcional com chave de conexão (usa a conexão da chave)."
                  },
                  "convert": {
                    "enum": [
                      "voice"
                    ],
                    "type": "string",
                    "description": "`voice`: converte para mensagem de voz (OGG/Opus)."
                  },
                  "purpose": {
                    "enum": [
                      "message",
                      "publication"
                    ],
                    "type": "string",
                    "description": "`message` (padrão) ou `publication`: aplica os limites do canal para essa finalidade (publicação do Instagram: JPEG até 8 MiB, vídeo até 300 MiB)."
                  }
                },
                "required": [
                  "file"
                ]
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "O arquivo."
                  },
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexão da mídia. Opcional com chave de conexão (usa a conexão da chave)."
                  },
                  "convert": {
                    "enum": [
                      "voice"
                    ],
                    "type": "string",
                    "description": "`voice`: converte para mensagem de voz (OGG/Opus)."
                  },
                  "purpose": {
                    "enum": [
                      "message",
                      "publication"
                    ],
                    "type": "string",
                    "description": "`message` (padrão) ou `publication`: aplica os limites do canal para essa finalidade (publicação do Instagram: JPEG até 8 MiB, vídeo até 300 MiB)."
                  }
                },
                "required": [
                  "file"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A mídia guardada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da mídia (`med_…`).",
                      "examples": [
                        "med_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão da mídia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "mime_type": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tipo do arquivo, ex.: `image/jpeg`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome do arquivo, quando há."
                    },
                    "size_bytes": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tamanho em bytes."
                    },
                    "sha256": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hash SHA-256 do conteúdo."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "stored",
                        "failed",
                        "purging"
                      ],
                      "type": "string",
                      "description": "Status: `pending`, `stored` ou `failed`."
                    },
                    "origin": {
                      "enum": [
                        "inbound",
                        "upload",
                        "converted"
                      ],
                      "type": "string",
                      "description": "Origem: `inbound` (recebida), `upload` ou `converted`."
                    },
                    "converted_from_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mídia original, quando esta é uma conversão."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a mídia foi gravada (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "mime_type",
                    "filename",
                    "size_bytes",
                    "sha256",
                    "status",
                    "origin",
                    "converted_from_id",
                    "created_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/media/{id}": {
      "get": {
        "operationId": "getMedia",
        "summary": "Obter uma mídia",
        "description": "Devolve os dados da mídia (tipo, tamanho, status). Permissão: `read`.",
        "tags": [
          "media"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da mídia (`med_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A mídia.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da mídia (`med_…`).",
                      "examples": [
                        "med_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão da mídia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "mime_type": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tipo do arquivo, ex.: `image/jpeg`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome do arquivo, quando há."
                    },
                    "size_bytes": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tamanho em bytes."
                    },
                    "sha256": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hash SHA-256 do conteúdo."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "stored",
                        "failed",
                        "purging"
                      ],
                      "type": "string",
                      "description": "Status: `pending`, `stored` ou `failed`."
                    },
                    "origin": {
                      "enum": [
                        "inbound",
                        "upload",
                        "converted"
                      ],
                      "type": "string",
                      "description": "Origem: `inbound` (recebida), `upload` ou `converted`."
                    },
                    "converted_from_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mídia original, quando esta é uma conversão."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a mídia foi gravada (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "mime_type",
                    "filename",
                    "size_bytes",
                    "sha256",
                    "status",
                    "origin",
                    "converted_from_id",
                    "created_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteMedia",
        "summary": "Excluir mídia",
        "description": "Apaga o arquivo do Messajo e, se ele já tinha subido, tenta apagar também na Meta (lá ele expira sozinho em 30 dias). Permissão: `send`.",
        "tags": [
          "media"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da mídia (`med_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmação da exclusão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da mídia (`med_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    },
                    "meta_deleted": {
                      "type": "boolean",
                      "description": "Se também saiu da Meta."
                    }
                  },
                  "required": [
                    "id",
                    "deleted",
                    "meta_deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/media/{id}/content": {
      "get": {
        "operationId": "getMediaContent",
        "summary": "Baixar uma mídia",
        "description": "Devolve os bytes da mídia. Mídia recebida que ainda não foi baixada da Meta é baixada na hora. Permissão: `read`.",
        "tags": [
          "media"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da mídia (`med_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O arquivo.",
            "content": {
              "*/*": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "*/*",
                  "description": "O arquivo."
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/media/{id}/link": {
      "post": {
        "operationId": "createMediaLink",
        "summary": "Criar link temporário",
        "description": "Gera um link assinado para baixar a mídia sem chave, válido de 60 segundos a 7 dias (padrão 1 hora). Permissão: `read`.",
        "tags": [
          "media"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da mídia (`med_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "expires_in_seconds": {
                    "type": "integer",
                    "minimum": 60,
                    "maximum": 604800,
                    "default": 3600,
                    "description": "Validade do link, de 60 a 604 800 segundos."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O link e quando ele expira.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "description": "Link assinado."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Quando o link expira (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "url",
                    "expires_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connection-links": {
      "get": {
        "operationId": "listConnectionLinks",
        "summary": "Listar links de conexão",
        "description": "Lista os links que permitem a uma pessoa de fora (sem conta no Messajo) conectar um número à organização. Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connection-links"
        ],
        "responses": {
          "200": {
            "description": "Os links de conexão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do link (`clk_…`).",
                            "examples": [
                              "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "channel": {
                            "enum": [
                              "whatsapp",
                              "instagram",
                              "messenger"
                            ],
                            "type": "string",
                            "description": "Canal a conectar (por enquanto, `whatsapp`)."
                          },
                          "mode": {
                            "anyOf": [
                              {
                                "enum": [
                                  "coex",
                                  "api_only",
                                  "any"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Modo: `coex`, `api_only` ou `any` (a pessoa escolhe)."
                          },
                          "label": {
                            "type": "string",
                            "description": "Nome do link, para a organização."
                          },
                          "token_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres do token."
                          },
                          "expires_at": {
                            "type": "string",
                            "description": "Quando o link expira (ISO 8601, UTC)."
                          },
                          "reusable": {
                            "type": "boolean",
                            "description": "`true` = vale para vários números; `false` = uso único."
                          },
                          "uses_count": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Conexões já feitas com o link."
                          },
                          "has_password": {
                            "type": "boolean",
                            "description": "Se o link pede senha."
                          },
                          "locale": {
                            "type": "string",
                            "description": "Idioma da página e do e-mail: `pt-BR`, `en-US` ou `es`."
                          },
                          "reconnect_connection_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conexão a reconectar, quando o link é de reconexão."
                          },
                          "recipient_email": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "E-mail para onde o link vai."
                          },
                          "status": {
                            "enum": [
                              "active",
                              "used",
                              "expired",
                              "revoked"
                            ],
                            "type": "string",
                            "description": "Status: `active`, `used`, `expired` ou `revoked`."
                          },
                          "last_sent_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último envio por e-mail (ISO 8601, UTC)."
                          },
                          "last_used_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último uso (ISO 8601, UTC)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando o link foi criado (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última alteração (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "channel",
                          "mode",
                          "label",
                          "token_last4",
                          "expires_at",
                          "reusable",
                          "uses_count",
                          "has_password",
                          "locale",
                          "reconnect_connection_id",
                          "recipient_email",
                          "status",
                          "last_sent_at",
                          "last_used_at",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createConnectionLink",
        "summary": "Criar link de conexão",
        "description": "Cria um link público de conexão, com validade de 1 hora a 30 dias, senha opcional e uso único ou reutilizável. A `url` aparece só nesta resposta (e no e-mail, se `recipient_email` for informado): o Messajo guarda apenas o hash do token. Para reconectar um número, informe `reconnect_connection_id`. Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connection-links"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "channel": {
                    "enum": [
                      "whatsapp",
                      "instagram",
                      "messenger"
                    ],
                    "type": "string",
                    "default": "whatsapp",
                    "description": "Canal a conectar (por enquanto, `whatsapp`)."
                  },
                  "mode": {
                    "enum": [
                      "coex",
                      "api_only",
                      "any"
                    ],
                    "type": "string",
                    "description": "Modo: `coex`, `api_only` ou `any` (a pessoa escolhe)."
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Nome do link, para a organização."
                  },
                  "expires_in_hours": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 720,
                    "default": 168,
                    "description": "Validade em horas, de 1 a 720 (padrão 168)."
                  },
                  "reusable": {
                    "type": "boolean",
                    "default": false,
                    "description": "`true` = vale para vários números; `false` = uso único."
                  },
                  "password": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 128,
                    "description": "Senha opcional, de 8 a 128 caracteres."
                  },
                  "locale": {
                    "enum": [
                      "pt-BR",
                      "en-US",
                      "es"
                    ],
                    "type": "string",
                    "description": "Idioma da página e do e-mail: `pt-BR`, `en-US` ou `es`."
                  },
                  "reconnect_connection_id": {
                    "type": "string",
                    "description": "Conexão a reconectar, quando o link é de reconexão."
                  },
                  "recipient_email": {
                    "type": "string",
                    "maxLength": 254,
                    "format": "email",
                    "description": "E-mail para onde o link vai."
                  }
                },
                "required": [
                  "label",
                  "locale"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O link criado, com a `url`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do link (`clk_…`).",
                      "examples": [
                        "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal a conectar (por enquanto, `whatsapp`)."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only",
                            "any"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo: `coex`, `api_only` ou `any` (a pessoa escolhe)."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do link, para a organização."
                    },
                    "token_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do token."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Quando o link expira (ISO 8601, UTC)."
                    },
                    "reusable": {
                      "type": "boolean",
                      "description": "`true` = vale para vários números; `false` = uso único."
                    },
                    "uses_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Conexões já feitas com o link."
                    },
                    "has_password": {
                      "type": "boolean",
                      "description": "Se o link pede senha."
                    },
                    "locale": {
                      "type": "string",
                      "description": "Idioma da página e do e-mail: `pt-BR`, `en-US` ou `es`."
                    },
                    "reconnect_connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão a reconectar, quando o link é de reconexão."
                    },
                    "recipient_email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "E-mail para onde o link vai."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "used",
                        "expired",
                        "revoked"
                      ],
                      "type": "string",
                      "description": "Status: `active`, `used`, `expired` ou `revoked`."
                    },
                    "last_sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último envio por e-mail (ISO 8601, UTC)."
                    },
                    "last_used_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último uso (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando o link foi criado (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    },
                    "url": {
                      "type": "string",
                      "description": "Endereço público do link. Só aparece ao criar ou reenviar."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "mode",
                    "label",
                    "token_last4",
                    "expires_at",
                    "reusable",
                    "uses_count",
                    "has_password",
                    "locale",
                    "reconnect_connection_id",
                    "recipient_email",
                    "status",
                    "last_sent_at",
                    "last_used_at",
                    "created_at",
                    "updated_at",
                    "url"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/connection-links/{id}": {
      "get": {
        "operationId": "getConnectionLink",
        "summary": "Obter um link de conexão",
        "description": "Devolve o link, sem o token. Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connection-links"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do link (`clk_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O link de conexão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do link (`clk_…`).",
                      "examples": [
                        "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal a conectar (por enquanto, `whatsapp`)."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only",
                            "any"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo: `coex`, `api_only` ou `any` (a pessoa escolhe)."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do link, para a organização."
                    },
                    "token_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do token."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Quando o link expira (ISO 8601, UTC)."
                    },
                    "reusable": {
                      "type": "boolean",
                      "description": "`true` = vale para vários números; `false` = uso único."
                    },
                    "uses_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Conexões já feitas com o link."
                    },
                    "has_password": {
                      "type": "boolean",
                      "description": "Se o link pede senha."
                    },
                    "locale": {
                      "type": "string",
                      "description": "Idioma da página e do e-mail: `pt-BR`, `en-US` ou `es`."
                    },
                    "reconnect_connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão a reconectar, quando o link é de reconexão."
                    },
                    "recipient_email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "E-mail para onde o link vai."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "used",
                        "expired",
                        "revoked"
                      ],
                      "type": "string",
                      "description": "Status: `active`, `used`, `expired` ou `revoked`."
                    },
                    "last_sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último envio por e-mail (ISO 8601, UTC)."
                    },
                    "last_used_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último uso (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando o link foi criado (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "mode",
                    "label",
                    "token_last4",
                    "expires_at",
                    "reusable",
                    "uses_count",
                    "has_password",
                    "locale",
                    "reconnect_connection_id",
                    "recipient_email",
                    "status",
                    "last_sent_at",
                    "last_used_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "revokeConnectionLink",
        "summary": "Revogar link de conexão",
        "description": "Revoga o link: ele deixa de abrir. Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connection-links"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do link (`clk_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O link revogado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do link (`clk_…`).",
                      "examples": [
                        "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal a conectar (por enquanto, `whatsapp`)."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only",
                            "any"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo: `coex`, `api_only` ou `any` (a pessoa escolhe)."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do link, para a organização."
                    },
                    "token_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do token."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Quando o link expira (ISO 8601, UTC)."
                    },
                    "reusable": {
                      "type": "boolean",
                      "description": "`true` = vale para vários números; `false` = uso único."
                    },
                    "uses_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Conexões já feitas com o link."
                    },
                    "has_password": {
                      "type": "boolean",
                      "description": "Se o link pede senha."
                    },
                    "locale": {
                      "type": "string",
                      "description": "Idioma da página e do e-mail: `pt-BR`, `en-US` ou `es`."
                    },
                    "reconnect_connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão a reconectar, quando o link é de reconexão."
                    },
                    "recipient_email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "E-mail para onde o link vai."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "used",
                        "expired",
                        "revoked"
                      ],
                      "type": "string",
                      "description": "Status: `active`, `used`, `expired` ou `revoked`."
                    },
                    "last_sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último envio por e-mail (ISO 8601, UTC)."
                    },
                    "last_used_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último uso (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando o link foi criado (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "mode",
                    "label",
                    "token_last4",
                    "expires_at",
                    "reusable",
                    "uses_count",
                    "has_password",
                    "locale",
                    "reconnect_connection_id",
                    "recipient_email",
                    "status",
                    "last_sent_at",
                    "last_used_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connection-links/{id}/send": {
      "post": {
        "operationId": "sendConnectionLink",
        "summary": "Enviar link por e-mail",
        "description": "Envia o link por e-mail, no idioma do link. Gera um token novo: a URL anterior deixa de valer. A senha nunca vai no e-mail. Permissão: `admin`. Exige chave da organização.",
        "tags": [
          "connection-links"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do link (`clk_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "recipient_email": {
                    "type": "string",
                    "maxLength": 254,
                    "format": "email",
                    "description": "E-mail para onde o link vai."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O link, com a `url` nova.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do link (`clk_…`).",
                      "examples": [
                        "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal a conectar (por enquanto, `whatsapp`)."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only",
                            "any"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo: `coex`, `api_only` ou `any` (a pessoa escolhe)."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nome do link, para a organização."
                    },
                    "token_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres do token."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Quando o link expira (ISO 8601, UTC)."
                    },
                    "reusable": {
                      "type": "boolean",
                      "description": "`true` = vale para vários números; `false` = uso único."
                    },
                    "uses_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Conexões já feitas com o link."
                    },
                    "has_password": {
                      "type": "boolean",
                      "description": "Se o link pede senha."
                    },
                    "locale": {
                      "type": "string",
                      "description": "Idioma da página e do e-mail: `pt-BR`, `en-US` ou `es`."
                    },
                    "reconnect_connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexão a reconectar, quando o link é de reconexão."
                    },
                    "recipient_email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "E-mail para onde o link vai."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "used",
                        "expired",
                        "revoked"
                      ],
                      "type": "string",
                      "description": "Status: `active`, `used`, `expired` ou `revoked`."
                    },
                    "last_sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último envio por e-mail (ISO 8601, UTC)."
                    },
                    "last_used_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último uso (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando o link foi criado (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    },
                    "url": {
                      "type": "string",
                      "description": "Endereço público do link. Só aparece ao criar ou reenviar."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "mode",
                    "label",
                    "token_last4",
                    "expires_at",
                    "reusable",
                    "uses_count",
                    "has_password",
                    "locale",
                    "reconnect_connection_id",
                    "recipient_email",
                    "status",
                    "last_sent_at",
                    "last_used_at",
                    "created_at",
                    "updated_at",
                    "url"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/messaging-profile": {
      "get": {
        "operationId": "getMessagingProfile",
        "summary": "Obter perfil de mensagens",
        "description": "Lê na Meta o perfil de mensagens da conta do Instagram ou da Página: ice breakers, menu fixo e, no Messenger, saudação e botão Começar. Campo não configurado vem `null`. Permissão: `read`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram ou do Messenger (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O perfil.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão do Instagram ou do Messenger (`con_…`)."
                    },
                    "channel": {
                      "enum": [
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "`instagram` ou `messenger`."
                    },
                    "ice_breakers": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Perguntas prontas da primeira conversa, por idioma (`locale`, `questions[{ question, payload }]`)."
                    },
                    "persistent_menu": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Menu fixo, por idioma (`locale`, `items[]`, `composer_input_disabled` só no Messenger)."
                    },
                    "greeting": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saudação antes da primeira mensagem, por idioma (`locale`, `text` até 160, aceita `{{user_first_name}}`). Só Messenger."
                    },
                    "get_started": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "payload": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "payload"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Botão Começar (`payload`). Só Messenger."
                    },
                    "synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando o perfil foi lido da Meta (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "connection_id",
                    "channel",
                    "synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "put": {
        "operationId": "updateMessagingProfile",
        "summary": "Alterar perfil de mensagens",
        "description": "Grava o perfil de mensagens de forma parcial: campo ausente não muda, `null` apaga. Ice breakers: até 4 perguntas por idioma; menu fixo: até 20 itens (`postback` ou `web_url`); cada lista precisa do idioma `default`. `greeting` e `get_started` só no Messenger (no Instagram: `422 type_not_supported_by_channel`); apagar `get_started` com o menu ativo é recusado. Permissão: `admin`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram ou do Messenger (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ice_breakers": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "locale": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "locale"
                          ],
                          "additionalProperties": {}
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Perguntas prontas da primeira conversa, por idioma (`locale`, `questions[{ question, payload }]`)."
                  },
                  "persistent_menu": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "locale": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "locale"
                          ],
                          "additionalProperties": {}
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Menu fixo, por idioma (`locale`, `items[]`, `composer_input_disabled` só no Messenger)."
                  },
                  "greeting": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "locale": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "locale"
                          ],
                          "additionalProperties": {}
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Saudação antes da primeira mensagem, por idioma (`locale`, `text` até 160, aceita `{{user_first_name}}`). Só Messenger."
                  },
                  "get_started": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "payload": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "payload"
                        ]
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Botão Começar (`payload`). Só Messenger."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O perfil relido da Meta.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão do Instagram ou do Messenger (`con_…`)."
                    },
                    "channel": {
                      "enum": [
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "`instagram` ou `messenger`."
                    },
                    "ice_breakers": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Perguntas prontas da primeira conversa, por idioma (`locale`, `questions[{ question, payload }]`)."
                    },
                    "persistent_menu": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Menu fixo, por idioma (`locale`, `items[]`, `composer_input_disabled` só no Messenger)."
                    },
                    "greeting": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saudação antes da primeira mensagem, por idioma (`locale`, `text` até 160, aceita `{{user_first_name}}`). Só Messenger."
                    },
                    "get_started": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "payload": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "payload"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Botão Começar (`payload`). Só Messenger."
                    },
                    "synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando o perfil foi lido da Meta (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "connection_id",
                    "channel",
                    "synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/welcome-flows": {
      "get": {
        "operationId": "listWelcomeFlows",
        "summary": "Listar fluxos de boas-vindas",
        "description": "Lista os fluxos de boas-vindas da conta do Instagram (anúncios que levam para o Direct). Permissão: `read`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram ou do Messenger (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Os fluxos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do fluxo na Meta."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nome do fluxo."
                          },
                          "messages": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "text": {
                                  "type": "string"
                                },
                                "quick_replies": {
                                  "type": "array",
                                  "items": {
                                    "type": "object",
                                    "properties": {
                                      "title": {
                                        "type": "string"
                                      },
                                      "payload": {
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "title",
                                      "payload"
                                    ]
                                  }
                                }
                              },
                              "required": [
                                "text",
                                "quick_replies"
                              ]
                            },
                            "description": "Mensagens do fluxo, na ordem."
                          },
                          "is_used_in_ad": {
                            "type": "boolean",
                            "description": "Fluxo usado em anúncio (não muda nem apaga)."
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "messages",
                          "is_used_in_ad"
                        ]
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createWelcomeFlow",
        "summary": "Criar fluxo de boas-vindas",
        "description": "Cria um fluxo de boas-vindas do Instagram: nome e mensagens com respostas rápidas. Permissão: `admin`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram ou do Messenger (`con_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Nome do fluxo."
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Texto da mensagem."
                        },
                        "quick_replies": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "title": {
                                "type": "string",
                                "description": "Texto do botão (até 20 caracteres)."
                              },
                              "payload": {
                                "type": "string",
                                "description": "Valor devolvido no webhook quando o contato toca."
                              }
                            },
                            "required": [
                              "title",
                              "payload"
                            ]
                          },
                          "description": "Respostas rápidas da mensagem (até 13)."
                        }
                      },
                      "required": [
                        "text"
                      ]
                    },
                    "description": "Mensagens do fluxo, na ordem."
                  }
                },
                "required": [
                  "name",
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O fluxo criado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do fluxo na Meta."
                    }
                  },
                  "required": [
                    "id"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/welcome-flows/{flow_id}": {
      "patch": {
        "operationId": "updateWelcomeFlow",
        "summary": "Alterar fluxo de boas-vindas",
        "description": "Troca o nome e as mensagens de um fluxo. Fluxo usado em anúncio não muda (`409 welcome_flow_in_use`). Permissão: `admin`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram ou do Messenger (`con_…`)."
            }
          },
          {
            "name": "flow_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do fluxo na Meta."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Nome do fluxo."
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Texto da mensagem."
                        },
                        "quick_replies": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "title": {
                                "type": "string",
                                "description": "Texto do botão (até 20 caracteres)."
                              },
                              "payload": {
                                "type": "string",
                                "description": "Valor devolvido no webhook quando o contato toca."
                              }
                            },
                            "required": [
                              "title",
                              "payload"
                            ]
                          },
                          "description": "Respostas rápidas da mensagem (até 13)."
                        }
                      },
                      "required": [
                        "text"
                      ]
                    },
                    "description": "Mensagens do fluxo, na ordem."
                  }
                },
                "required": [
                  "name",
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O fluxo alterado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do fluxo na Meta."
                    }
                  },
                  "required": [
                    "id"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteWelcomeFlow",
        "summary": "Apagar fluxo de boas-vindas",
        "description": "Apaga um fluxo. Fluxo usado em anúncio não sai (`409 welcome_flow_in_use`). Permissão: `admin`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram ou do Messenger (`con_…`)."
            }
          },
          {
            "name": "flow_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do fluxo na Meta."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do fluxo na Meta."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/posts": {
      "get": {
        "operationId": "listPosts",
        "summary": "Listar posts",
        "description": "Lista os posts da conta do Instagram, ao vivo na Meta, do mais novo para o mais antigo, com tipo, legenda, link, curtidas e comentários. Permissão: `read`.",
        "tags": [
          "posts"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de posts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do post (mídia) na Meta."
                          }
                        },
                        "required": [
                          "id"
                        ],
                        "additionalProperties": {},
                        "description": "Post como a Meta devolve: `id`, `caption`, `media_type`, `media_product_type`, `permalink`, `timestamp`, `like_count`, `comments_count`, `thumbnail_url`, `media_url`."
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/posts/{post_id}": {
      "get": {
        "operationId": "getPost",
        "summary": "Obter um post",
        "description": "Devolve um post da conta, ao vivo na Meta. Post de outra conta: `404`. Permissão: `read`.",
        "tags": [
          "posts"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "post_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do post (mídia) na Meta."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O post.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do post (mídia) na Meta."
                    }
                  },
                  "required": [
                    "id"
                  ],
                  "additionalProperties": {},
                  "description": "Post como a Meta devolve: `id`, `caption`, `media_type`, `media_product_type`, `permalink`, `timestamp`, `like_count`, `comments_count`, `thumbnail_url`, `media_url`."
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/publishing-limit": {
      "get": {
        "operationId": "getPublishingLimit",
        "summary": "Cota de publicação",
        "description": "Lê na Meta quantas publicações a conta já fez na janela da cota (a Meta limita por 24 h). Permissão: `read`.",
        "tags": [
          "posts"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A cota.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "quota_usage": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Publicações feitas na janela da cota."
                    },
                    "quota_total": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Publicações permitidas na janela."
                    },
                    "quota_duration_s": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Duração da janela, em segundos."
                    }
                  },
                  "required": [
                    "quota_usage",
                    "quota_total",
                    "quota_duration_s"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/posts/{post_id}/comments": {
      "get": {
        "operationId": "listPostComments",
        "summary": "Listar comentários de um post",
        "description": "Lista os comentários de um post do Instagram, ao vivo na Meta, com as respostas e o estado local (`private_replied_at`, `deleted_at`). Exige a permissão `instagram_manage_comments` da conta (`403 instagram_scope_missing`). Permissão: `read`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "post_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do post (mídia) na Meta."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de comentários.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id"
                        ],
                        "additionalProperties": {},
                        "description": "Comentário como a Meta devolve, com `comment_id`, `private_replied_at` e `deleted_at` do Messajo."
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/comments/{comment_id}": {
      "get": {
        "operationId": "getComment",
        "summary": "Obter um comentário",
        "description": "Devolve um comentário ou menção gravado pelo Messajo (`cmt_…`). Permissão: `read`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do comentário no Messajo (`cmt_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O comentário.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do comentário no Messajo (`cmt_…`).",
                      "examples": [
                        "cmt_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do comentário na Meta."
                    },
                    "kind": {
                      "enum": [
                        "comment",
                        "live_comment",
                        "mention"
                      ],
                      "type": "string",
                      "description": "`comment`, `live_comment` (de uma live) ou `mention`."
                    },
                    "text": {
                      "type": "string",
                      "description": "Texto."
                    },
                    "parent_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Comentário pai (na Meta), quando é resposta."
                    },
                    "from": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "username": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "username"
                      ],
                      "description": "Quem escreveu."
                    },
                    "from_self": {
                      "type": "boolean",
                      "description": "`true` quando a própria conta escreveu."
                    },
                    "post": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "product_type": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "product_type"
                      ],
                      "description": "Post do comentário: ID e tipo (`FEED`, `REELS`, `STORY`)."
                    },
                    "hidden": {
                      "type": "boolean",
                      "description": "Comentário oculto."
                    },
                    "reply_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Respostas enviadas pelo Messajo."
                    },
                    "private_replied_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a resposta no Direct foi enviada (ISO 8601, UTC)."
                    },
                    "deleted_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi apagado (ISO 8601, UTC)."
                    },
                    "occurred_at": {
                      "type": "string",
                      "description": "Quando aconteceu (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "kind",
                    "text",
                    "parent_id",
                    "from",
                    "from_self",
                    "post",
                    "hidden",
                    "reply_count",
                    "private_replied_at",
                    "deleted_at",
                    "occurred_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteComment",
        "summary": "Apagar um comentário",
        "description": "Apaga um comentário em mídia da própria conta; em mídia de outra conta (menção): `409 comment_not_owned`. Gera `comment.deleted`. Permissão: `send`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do comentário no Messajo (`cmt_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do comentário no Messajo (`cmt_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/comments/{comment_id}/replies": {
      "post": {
        "operationId": "replyComment",
        "summary": "Responder um comentário",
        "description": "Responde em público a um comentário (até 2200 caracteres). Não é idempotente na Meta: use `Idempotency-Key` para repetir sem duplicar. Gera `comment.replied`. Permissão: `send`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do comentário no Messajo (`cmt_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2200,
                    "description": "Texto da resposta (até 2200 caracteres)."
                  }
                },
                "required": [
                  "message"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A resposta criada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da resposta na Meta."
                    }
                  },
                  "required": [
                    "id"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/comments/{comment_id}/private-reply": {
      "post": {
        "operationId": "privateReplyComment",
        "summary": "Responder no Direct",
        "description": "Manda uma mensagem no Direct para quem comentou: `text`, `buttons` ou `cards`, no mesmo formato de `POST /messages`. Uma vez por comentário (`409 private_reply_already_sent`), até 7 dias depois do comentário (`422 private_reply_window_closed`), sem depender da janela de 24 h. Abre a conversa com o contato e gera `comment.private_replied` e `message.sent`. Permissão: `send`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do comentário no Messajo (`cmt_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "minLength": 1,
                    "description": "`text`, `buttons` ou `cards`, com o campo do mesmo nome como em `POST /messages`."
                  }
                },
                "required": [
                  "type"
                ],
                "additionalProperties": {}
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A mensagem enviada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da mensagem no Messajo (`msg_…`)."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID da mensagem na Meta (`wamid`)."
                    },
                    "conversation_id": {
                      "type": "string",
                      "description": "Conversa da mensagem."
                    },
                    "contact_id": {
                      "type": "string",
                      "description": "Contato destinatário."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a mensagem foi gravada (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "conversation_id",
                    "contact_id",
                    "created_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/comments/{comment_id}/hide": {
      "post": {
        "operationId": "hideComment",
        "summary": "Ocultar ou mostrar um comentário",
        "description": "Oculta (`hidden: true`) ou volta a mostrar um comentário. Gera `comment.hidden` ou `comment.unhidden`. Permissão: `send`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do comentário no Messajo (`cmt_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "hidden": {
                    "type": "boolean",
                    "description": "Comentário oculto."
                  }
                },
                "required": [
                  "hidden"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O comentário atualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do comentário no Messajo (`cmt_…`).",
                      "examples": [
                        "cmt_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do comentário na Meta."
                    },
                    "kind": {
                      "enum": [
                        "comment",
                        "live_comment",
                        "mention"
                      ],
                      "type": "string",
                      "description": "`comment`, `live_comment` (de uma live) ou `mention`."
                    },
                    "text": {
                      "type": "string",
                      "description": "Texto."
                    },
                    "parent_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Comentário pai (na Meta), quando é resposta."
                    },
                    "from": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "username": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "username"
                      ],
                      "description": "Quem escreveu."
                    },
                    "from_self": {
                      "type": "boolean",
                      "description": "`true` quando a própria conta escreveu."
                    },
                    "post": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "product_type": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "product_type"
                      ],
                      "description": "Post do comentário: ID e tipo (`FEED`, `REELS`, `STORY`)."
                    },
                    "hidden": {
                      "type": "boolean",
                      "description": "Comentário oculto."
                    },
                    "reply_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Respostas enviadas pelo Messajo."
                    },
                    "private_replied_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a resposta no Direct foi enviada (ISO 8601, UTC)."
                    },
                    "deleted_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi apagado (ISO 8601, UTC)."
                    },
                    "occurred_at": {
                      "type": "string",
                      "description": "Quando aconteceu (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "kind",
                    "text",
                    "parent_id",
                    "from",
                    "from_self",
                    "post",
                    "hidden",
                    "reply_count",
                    "private_replied_at",
                    "deleted_at",
                    "occurred_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/mentions": {
      "get": {
        "operationId": "listMentions",
        "summary": "Listar menções",
        "description": "Lista as menções à conta (em comentários, legendas e stories) gravadas pelo Messajo, da mais nova para a mais antiga. Permissão: `read`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de menções.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da menção no Messajo (`cmt_…`)."
                          },
                          "source": {
                            "enum": [
                              "comment",
                              "caption",
                              "story"
                            ],
                            "type": "string",
                            "description": "Onde a conta foi mencionada: `comment`, `caption` ou `story`."
                          },
                          "post_id": {
                            "type": "string",
                            "description": "ID do post (mídia) na Meta."
                          },
                          "comment_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID do comentário na Meta."
                          },
                          "from": {
                            "type": "object",
                            "properties": {
                              "username": {
                                "anyOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              }
                            },
                            "required": [
                              "username"
                            ],
                            "description": "Quem escreveu."
                          },
                          "text": {
                            "type": "string",
                            "description": "Texto."
                          },
                          "occurred_at": {
                            "type": "string",
                            "description": "Quando aconteceu (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "source",
                          "post_id",
                          "comment_id",
                          "from",
                          "text",
                          "occurred_at"
                        ],
                        "description": "Menção à conta."
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/insights": {
      "get": {
        "operationId": "getAccountInsights",
        "summary": "Insights da conta",
        "description": "Métricas da conta do Instagram. `period=day`: `reach`, `views`, `accounts_engaged`, `total_interactions`, `likes`, `comments`, `shares`, `saves`, `replies`, `reposts`, `follows_and_unfollows`, `profile_links_taps`. `period=lifetime` com `timeframe` (`this_week`, `this_month`): `follower_demographics`, `engaged_audience_demographics`. `impressions` foi descontinuada pela Meta (`422 validation_failed`). Resultado guardado por 15 min. Exige `instagram_manage_insights`. Permissão: `read`.",
        "tags": [
          "insights"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "metric",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Métricas separadas por vírgula."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "period",
            "in": "query",
            "required": true,
            "schema": {
              "enum": [
                "day",
                "lifetime"
              ],
              "type": "string",
              "description": "`day` ou `lifetime`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "metric_type",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "time_series",
                "total_value"
              ],
              "type": "string",
              "description": "`time_series` ou `total_value`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "breakdown",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "description": "Quebra da métrica (por exemplo `city`, `age`, `gender`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "timeframe",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "description": "Janela das demográficas: `this_week` ou `this_month`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Início (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fim (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "As métricas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "metric": {
                            "type": "string",
                            "description": "Nome da métrica."
                          },
                          "period": {
                            "type": "string",
                            "description": "`day` ou `lifetime`."
                          },
                          "total_value": {
                            "description": "Valor total, quando a Meta devolve."
                          },
                          "values": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "value": {},
                                "end_time": {
                                  "type": "string"
                                }
                              }
                            },
                            "description": "Valores por período (`value`, `end_time`)."
                          },
                          "breakdowns": {
                            "type": "array",
                            "items": {
                              "anyOf": [
                                {},
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "description": "Quebras, como a Meta devolve."
                          }
                        },
                        "required": [
                          "metric",
                          "period",
                          "values",
                          "breakdowns"
                        ],
                        "description": "Uma métrica."
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/posts/{post_id}/insights": {
      "get": {
        "operationId": "getPostInsights",
        "summary": "Insights de um post",
        "description": "Métricas de um post, pelo tipo dele (feed, Reels ou story). Story vencido sai do último retrato guardado (`source: snapshot`). Filho de carrossel ou audiência pequena: `422 insights_not_available`. Permissão: `read`.",
        "tags": [
          "insights"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexão do Instagram (`con_…`)."
            }
          },
          {
            "name": "post_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do post (mídia) na Meta."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "As métricas do post.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "media_id": {
                      "type": "string",
                      "description": "ID do post (mídia) na Meta."
                    },
                    "product_type": {
                      "enum": [
                        "FEED",
                        "REELS",
                        "STORY"
                      ],
                      "type": "string",
                      "description": "Tipo do post: `FEED`, `REELS` ou `STORY`."
                    },
                    "source": {
                      "enum": [
                        "live",
                        "snapshot"
                      ],
                      "type": "string",
                      "description": "`live` (lido agora) ou `snapshot` (retrato de um story que já venceu)."
                    },
                    "captured_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando o retrato foi tirado (ISO 8601, UTC)."
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "metric": {
                            "type": "string",
                            "description": "Nome da métrica."
                          },
                          "period": {
                            "type": "string",
                            "description": "`day` ou `lifetime`."
                          },
                          "total_value": {
                            "description": "Valor total, quando a Meta devolve."
                          },
                          "values": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "value": {},
                                "end_time": {
                                  "type": "string"
                                }
                              }
                            },
                            "description": "Valores por período (`value`, `end_time`)."
                          },
                          "breakdowns": {
                            "type": "array",
                            "items": {
                              "anyOf": [
                                {},
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "description": "Quebras, como a Meta devolve."
                          }
                        },
                        "required": [
                          "metric",
                          "period",
                          "values",
                          "breakdowns"
                        ],
                        "description": "Uma métrica."
                      }
                    }
                  },
                  "required": [
                    "media_id",
                    "product_type",
                    "source",
                    "captured_at",
                    "data"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/publications": {
      "post": {
        "operationId": "createPublication",
        "summary": "Criar publicação",
        "description": "Publica no Instagram na hora ou agenda (`scheduled_at` entre 1 min e 75 dias à frente). `photo`: 1 imagem; `video` e `reel`: 1 vídeo (vira Reels); `carousel`: 2 a 20 itens; `story`: 1 imagem ou vídeo. Legenda até 2200 caracteres, 30 hashtags e 20 menções. Cada item é um `media_id` (de `POST /media` com `purpose=publication`) ou uma `url` https pública. Imagem PNG/WebP é convertida para JPEG. A publicação nunca é repetida às cegas. Use `Idempotency-Key` para não criar duas. Gera `publication.published` ou `publication.failed`. Exige `instagram_content_publish`. Permissão: `send`.",
        "tags": [
          "publications"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexão do Instagram (`con_…`)."
                  },
                  "type": {
                    "enum": [
                      "photo",
                      "video",
                      "carousel",
                      "reel",
                      "story"
                    ],
                    "type": "string",
                    "description": "`photo`, `video`, `carousel`, `reel` ou `story`."
                  },
                  "caption": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Legenda."
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "properties": {
                        "media_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Mídia guardada no Messajo (`med_…`)."
                        },
                        "url": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL https pública que a Meta baixa."
                        },
                        "alt_text": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Texto alternativo da imagem."
                        },
                        "user_tags": {
                          "type": "array",
                          "items": {},
                          "description": "Marcações de pessoas, no formato da Meta."
                        }
                      },
                      "description": "Uma mídia: `media_id` ou `url`."
                    },
                    "description": "Mídias da publicação, na ordem."
                  },
                  "scheduled_at": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "date-time",
                        "description": "Horário agendado (ISO 8601); vazio ou `null` = publicar já."
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "share_to_feed": {
                    "type": "boolean",
                    "description": "Reels também aparece no feed."
                  },
                  "cover": {
                    "type": "string",
                    "minLength": 1,
                    "description": "URL da capa do Reels."
                  },
                  "thumb_offset_ms": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Quadro da capa do vídeo, em ms."
                  },
                  "collaborators": {
                    "type": "array",
                    "maxItems": 3,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": "Até 3 contas colaboradoras (@)."
                  },
                  "location_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID do local na Meta."
                  },
                  "audio_name": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Nome do áudio do Reels."
                  }
                },
                "required": [
                  "type",
                  "items"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A publicação criada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da publicação (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão do Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` ou `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Legenda."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "media_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "kind": {
                            "enum": [
                              "image",
                              "video"
                            ],
                            "type": "string"
                          },
                          "alt_text": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "user_tags": {
                            "type": "array",
                            "items": {
                              "anyOf": [
                                {},
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          }
                        },
                        "required": [
                          "media_id",
                          "url",
                          "kind",
                          "alt_text",
                          "user_tags"
                        ]
                      },
                      "description": "Mídias da publicação, na ordem."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "Reels também aparece no feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL da capa do Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Quadro da capa do vídeo, em ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Até 3 contas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID do local na Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nome do áudio do Reels."
                        }
                      },
                      "description": "Opções da publicação (`share_to_feed`, `cover`, `thumb_offset_ms`, `collaborators`, `location_id`, `audio_name`)."
                    },
                    "status": {
                      "enum": [
                        "scheduled",
                        "queued",
                        "creating",
                        "processing",
                        "publishing",
                        "published",
                        "failed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "`scheduled`, `queued`, `creating`, `processing`, `publishing`, `published`, `failed` ou `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horário agendado (ISO 8601); vazio ou `null` = publicar já."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do post publicado na Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Link do post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi publicado (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último erro, quando falhou."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Tentativas feitas."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última mudança (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "type",
                    "caption",
                    "items",
                    "options",
                    "status",
                    "scheduled_at",
                    "external_media_id",
                    "permalink",
                    "published_at",
                    "error",
                    "attempts",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      },
      "get": {
        "operationId": "listPublications",
        "summary": "Listar publicações",
        "description": "Lista as publicações da organização, das mais novas para as mais antigas, com filtros por conexão, status e horário (`since`/`until`). Permissão: `read`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Conexão do Instagram (`con_…`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "scheduled",
                "queued",
                "creating",
                "processing",
                "publishing",
                "published",
                "failed",
                "canceled"
              ],
              "type": "string",
              "description": "`scheduled`, `queued`, `creating`, `processing`, `publishing`, `published`, `failed` ou `canceled`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Agendadas ou criadas a partir de (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Agendadas ou criadas até (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "As publicações.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da publicação (`pub_…`).",
                            "examples": [
                              "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "Conexão do Instagram (`con_…`)."
                          },
                          "type": {
                            "enum": [
                              "photo",
                              "video",
                              "carousel",
                              "reel",
                              "story"
                            ],
                            "type": "string",
                            "description": "`photo`, `video`, `carousel`, `reel` ou `story`."
                          },
                          "caption": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Legenda."
                          },
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "media_id": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "url": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "kind": {
                                  "enum": [
                                    "image",
                                    "video"
                                  ],
                                  "type": "string"
                                },
                                "alt_text": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "user_tags": {
                                  "type": "array",
                                  "items": {
                                    "anyOf": [
                                      {},
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                }
                              },
                              "required": [
                                "media_id",
                                "url",
                                "kind",
                                "alt_text",
                                "user_tags"
                              ]
                            },
                            "description": "Mídias da publicação, na ordem."
                          },
                          "options": {
                            "type": "object",
                            "properties": {
                              "share_to_feed": {
                                "type": "boolean",
                                "description": "Reels também aparece no feed."
                              },
                              "cover": {
                                "type": "string",
                                "minLength": 1,
                                "description": "URL da capa do Reels."
                              },
                              "thumb_offset_ms": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991,
                                "description": "Quadro da capa do vídeo, em ms."
                              },
                              "collaborators": {
                                "type": "array",
                                "maxItems": 3,
                                "items": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "description": "Até 3 contas colaboradoras (@)."
                              },
                              "location_id": {
                                "type": "string",
                                "minLength": 1,
                                "description": "ID do local na Meta."
                              },
                              "audio_name": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Nome do áudio do Reels."
                              }
                            },
                            "description": "Opções da publicação (`share_to_feed`, `cover`, `thumb_offset_ms`, `collaborators`, `location_id`, `audio_name`)."
                          },
                          "status": {
                            "enum": [
                              "scheduled",
                              "queued",
                              "creating",
                              "processing",
                              "publishing",
                              "published",
                              "failed",
                              "canceled"
                            ],
                            "type": "string",
                            "description": "`scheduled`, `queued`, `creating`, `processing`, `publishing`, `published`, `failed` ou `canceled`."
                          },
                          "scheduled_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Horário agendado (ISO 8601); vazio ou `null` = publicar já."
                          },
                          "external_media_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID do post publicado na Meta."
                          },
                          "permalink": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Link do post publicado."
                          },
                          "published_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando foi publicado (ISO 8601, UTC)."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último erro, quando falhou."
                          },
                          "attempts": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Tentativas feitas."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Criação (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última mudança (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "connection_id",
                          "type",
                          "caption",
                          "items",
                          "options",
                          "status",
                          "scheduled_at",
                          "external_media_id",
                          "permalink",
                          "published_at",
                          "error",
                          "attempts",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/publications/{id}": {
      "get": {
        "operationId": "getPublication",
        "summary": "Obter uma publicação",
        "description": "Devolve a publicação com status, tentativas, erro e, depois de publicada, o ID e o link do post. Permissão: `read`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da publicação (`pub_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A publicação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da publicação (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão do Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` ou `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Legenda."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "media_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "kind": {
                            "enum": [
                              "image",
                              "video"
                            ],
                            "type": "string"
                          },
                          "alt_text": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "user_tags": {
                            "type": "array",
                            "items": {
                              "anyOf": [
                                {},
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          }
                        },
                        "required": [
                          "media_id",
                          "url",
                          "kind",
                          "alt_text",
                          "user_tags"
                        ]
                      },
                      "description": "Mídias da publicação, na ordem."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "Reels também aparece no feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL da capa do Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Quadro da capa do vídeo, em ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Até 3 contas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID do local na Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nome do áudio do Reels."
                        }
                      },
                      "description": "Opções da publicação (`share_to_feed`, `cover`, `thumb_offset_ms`, `collaborators`, `location_id`, `audio_name`)."
                    },
                    "status": {
                      "enum": [
                        "scheduled",
                        "queued",
                        "creating",
                        "processing",
                        "publishing",
                        "published",
                        "failed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "`scheduled`, `queued`, `creating`, `processing`, `publishing`, `published`, `failed` ou `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horário agendado (ISO 8601); vazio ou `null` = publicar já."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do post publicado na Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Link do post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi publicado (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último erro, quando falhou."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Tentativas feitas."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última mudança (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "type",
                    "caption",
                    "items",
                    "options",
                    "status",
                    "scheduled_at",
                    "external_media_id",
                    "permalink",
                    "published_at",
                    "error",
                    "attempts",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updatePublication",
        "summary": "Alterar publicação agendada",
        "description": "Altera legenda, itens, horário ou opções de uma publicação `scheduled` ou `queued`; campo ausente não muda. `scheduled_at: null` publica já. Outros status: `409 publication_not_editable`. Permissão: `send`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da publicação (`pub_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "caption": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Legenda."
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "properties": {
                        "media_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Mídia guardada no Messajo (`med_…`)."
                        },
                        "url": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL https pública que a Meta baixa."
                        },
                        "alt_text": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Texto alternativo da imagem."
                        },
                        "user_tags": {
                          "type": "array",
                          "items": {},
                          "description": "Marcações de pessoas, no formato da Meta."
                        }
                      },
                      "description": "Uma mídia: `media_id` ou `url`."
                    },
                    "description": "Mídias da publicação, na ordem."
                  },
                  "scheduled_at": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "date-time",
                        "description": "Horário agendado (ISO 8601); vazio ou `null` = publicar já."
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "share_to_feed": {
                    "type": "boolean",
                    "description": "Reels também aparece no feed."
                  },
                  "cover": {
                    "type": "string",
                    "minLength": 1,
                    "description": "URL da capa do Reels."
                  },
                  "thumb_offset_ms": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Quadro da capa do vídeo, em ms."
                  },
                  "collaborators": {
                    "type": "array",
                    "maxItems": 3,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": "Até 3 contas colaboradoras (@)."
                  },
                  "location_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID do local na Meta."
                  },
                  "audio_name": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Nome do áudio do Reels."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A publicação alterada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da publicação (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão do Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` ou `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Legenda."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "media_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "kind": {
                            "enum": [
                              "image",
                              "video"
                            ],
                            "type": "string"
                          },
                          "alt_text": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "user_tags": {
                            "type": "array",
                            "items": {
                              "anyOf": [
                                {},
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          }
                        },
                        "required": [
                          "media_id",
                          "url",
                          "kind",
                          "alt_text",
                          "user_tags"
                        ]
                      },
                      "description": "Mídias da publicação, na ordem."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "Reels também aparece no feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL da capa do Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Quadro da capa do vídeo, em ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Até 3 contas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID do local na Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nome do áudio do Reels."
                        }
                      },
                      "description": "Opções da publicação (`share_to_feed`, `cover`, `thumb_offset_ms`, `collaborators`, `location_id`, `audio_name`)."
                    },
                    "status": {
                      "enum": [
                        "scheduled",
                        "queued",
                        "creating",
                        "processing",
                        "publishing",
                        "published",
                        "failed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "`scheduled`, `queued`, `creating`, `processing`, `publishing`, `published`, `failed` ou `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horário agendado (ISO 8601); vazio ou `null` = publicar já."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do post publicado na Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Link do post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi publicado (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último erro, quando falhou."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Tentativas feitas."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última mudança (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "type",
                    "caption",
                    "items",
                    "options",
                    "status",
                    "scheduled_at",
                    "external_media_id",
                    "permalink",
                    "published_at",
                    "error",
                    "attempts",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/publications/{id}/cancel": {
      "post": {
        "operationId": "cancelPublication",
        "summary": "Cancelar publicação",
        "description": "Cancela uma publicação `scheduled` ou `queued`. Outros status: `409 publication_not_editable`. Permissão: `send`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da publicação (`pub_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A publicação cancelada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da publicação (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão do Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` ou `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Legenda."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "media_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "kind": {
                            "enum": [
                              "image",
                              "video"
                            ],
                            "type": "string"
                          },
                          "alt_text": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "user_tags": {
                            "type": "array",
                            "items": {
                              "anyOf": [
                                {},
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          }
                        },
                        "required": [
                          "media_id",
                          "url",
                          "kind",
                          "alt_text",
                          "user_tags"
                        ]
                      },
                      "description": "Mídias da publicação, na ordem."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "Reels também aparece no feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL da capa do Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Quadro da capa do vídeo, em ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Até 3 contas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID do local na Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nome do áudio do Reels."
                        }
                      },
                      "description": "Opções da publicação (`share_to_feed`, `cover`, `thumb_offset_ms`, `collaborators`, `location_id`, `audio_name`)."
                    },
                    "status": {
                      "enum": [
                        "scheduled",
                        "queued",
                        "creating",
                        "processing",
                        "publishing",
                        "published",
                        "failed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "`scheduled`, `queued`, `creating`, `processing`, `publishing`, `published`, `failed` ou `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horário agendado (ISO 8601); vazio ou `null` = publicar já."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do post publicado na Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Link do post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi publicado (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último erro, quando falhou."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Tentativas feitas."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última mudança (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "type",
                    "caption",
                    "items",
                    "options",
                    "status",
                    "scheduled_at",
                    "external_media_id",
                    "permalink",
                    "published_at",
                    "error",
                    "attempts",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/publications/{id}/retry": {
      "post": {
        "operationId": "retryPublication",
        "summary": "Tentar de novo",
        "description": "Recoloca na fila uma publicação `failed`, com contêineres novos. Não vale quando o resultado ficou incerto. Permissão: `send`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da publicação (`pub_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A publicação na fila.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da publicação (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexão do Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` ou `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Legenda."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "media_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "kind": {
                            "enum": [
                              "image",
                              "video"
                            ],
                            "type": "string"
                          },
                          "alt_text": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "user_tags": {
                            "type": "array",
                            "items": {
                              "anyOf": [
                                {},
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          }
                        },
                        "required": [
                          "media_id",
                          "url",
                          "kind",
                          "alt_text",
                          "user_tags"
                        ]
                      },
                      "description": "Mídias da publicação, na ordem."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "Reels também aparece no feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL da capa do Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Quadro da capa do vídeo, em ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Até 3 contas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID do local na Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nome do áudio do Reels."
                        }
                      },
                      "description": "Opções da publicação (`share_to_feed`, `cover`, `thumb_offset_ms`, `collaborators`, `location_id`, `audio_name`)."
                    },
                    "status": {
                      "enum": [
                        "scheduled",
                        "queued",
                        "creating",
                        "processing",
                        "publishing",
                        "published",
                        "failed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "`scheduled`, `queued`, `creating`, `processing`, `publishing`, `published`, `failed` ou `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horário agendado (ISO 8601); vazio ou `null` = publicar já."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do post publicado na Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Link do post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi publicado (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último erro, quando falhou."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Tentativas feitas."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última mudança (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "type",
                    "caption",
                    "items",
                    "options",
                    "status",
                    "scheduled_at",
                    "external_media_id",
                    "permalink",
                    "published_at",
                    "error",
                    "attempts",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/conversations": {
      "get": {
        "operationId": "listConversations",
        "summary": "Listar conversas",
        "description": "Lista as conversas da organização, da última mensagem mais recente para a mais antiga. Chave presa a conexões vê só as conversas delas. Permissão: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "Cursor opaco da página seguinte: o `next_cursor` da resposta anterior, com os mesmos filtros. Adulterado ou de outra rota → `400 invalid_cursor`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "contact_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do contato."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "window",
            "in": "query",
            "schema": {
              "enum": [
                "open",
                "closed"
              ],
              "type": "string",
              "description": "`open` = janela de atendimento aberta; `closed` = fechada."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Última mensagem a partir desta data (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Última mensagem até esta data (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de conversas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da conversa."
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID da conexão."
                          },
                          "channel": {
                            "enum": [
                              "whatsapp",
                              "instagram",
                              "messenger"
                            ],
                            "type": "string",
                            "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                          },
                          "contact": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "description": "ID do contato."
                              },
                              "display_name": {
                                "anyOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ],
                                "description": "Nome do contato, quando conhecido."
                              }
                            },
                            "required": [
                              "id",
                              "display_name"
                            ],
                            "description": "Contato da conversa."
                          },
                          "last_message_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última mensagem da conversa (ISO 8601, UTC)."
                          },
                          "last_inbound_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última mensagem recebida do contato (ISO 8601, UTC)."
                          },
                          "last_outbound_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última mensagem enviada ao contato (ISO 8601, UTC)."
                          },
                          "window_ends_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Fim da janela de atendimento de 24 h (ISO 8601, UTC)."
                          },
                          "extended_window_ends_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Fim da janela estendida (ISO 8601, UTC); `null` = sem janela estendida."
                          },
                          "extended_window_kind": {
                            "anyOf": [
                              {
                                "enum": [
                                  "human_agent",
                                  "ad_referral"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Tipo da janela estendida: `human_agent` ou `ad_referral`."
                          },
                          "window_open": {
                            "type": "boolean",
                            "description": "`true` enquanto a janela de atendimento está aberta."
                          },
                          "last_sequence": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Número de sequência do último evento da conversa."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Data de criação (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "connection_id",
                          "channel",
                          "contact",
                          "last_message_at",
                          "last_inbound_at",
                          "last_outbound_at",
                          "window_ends_at",
                          "extended_window_ends_at",
                          "extended_window_kind",
                          "window_open",
                          "last_sequence",
                          "created_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/conversations/{id}": {
      "get": {
        "operationId": "getConversation",
        "summary": "Obter conversa",
        "description": "Retorna uma conversa, com a janela de atendimento. Permissão: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conversa."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A conversa.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da conversa."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão."
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                    },
                    "contact": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "ID do contato."
                        },
                        "display_name": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Nome do contato, quando conhecido."
                        }
                      },
                      "required": [
                        "id",
                        "display_name"
                      ],
                      "description": "Contato da conversa."
                    },
                    "last_message_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última mensagem da conversa (ISO 8601, UTC)."
                    },
                    "last_inbound_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última mensagem recebida do contato (ISO 8601, UTC)."
                    },
                    "last_outbound_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última mensagem enviada ao contato (ISO 8601, UTC)."
                    },
                    "window_ends_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fim da janela de atendimento de 24 h (ISO 8601, UTC)."
                    },
                    "extended_window_ends_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fim da janela estendida (ISO 8601, UTC); `null` = sem janela estendida."
                    },
                    "extended_window_kind": {
                      "anyOf": [
                        {
                          "enum": [
                            "human_agent",
                            "ad_referral"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tipo da janela estendida: `human_agent` ou `ad_referral`."
                    },
                    "window_open": {
                      "type": "boolean",
                      "description": "`true` enquanto a janela de atendimento está aberta."
                    },
                    "last_sequence": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Número de sequência do último evento da conversa."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "channel",
                    "contact",
                    "last_message_at",
                    "last_inbound_at",
                    "last_outbound_at",
                    "window_ends_at",
                    "extended_window_ends_at",
                    "extended_window_kind",
                    "window_open",
                    "last_sequence",
                    "created_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/conversations/{id}/messages": {
      "get": {
        "operationId": "listConversationMessages",
        "summary": "Listar mensagens da conversa",
        "description": "Lista as mensagens de uma conversa dentro da retenção da organização (padrão: da mais nova para a mais antiga). Permissão: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conversa."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "Cursor opaco da página seguinte: o `next_cursor` da resposta anterior, com os mesmos filtros. Adulterado ou de outra rota → `400 invalid_cursor`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "order",
            "in": "query",
            "schema": {
              "enum": [
                "desc",
                "asc"
              ],
              "type": "string",
              "default": "desc",
              "description": "Ordem: `desc` (padrão, mais nova primeiro) ou `asc`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "enum": [
                "inbound",
                "outbound"
              ],
              "type": "string",
              "description": "Direção: `inbound` (recebida) ou `outbound` (enviada)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Tipo do conteúdo, ex.: `text`, `image`, `template`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Início do intervalo (ISO 8601). Padrão e limite: agora menos a retenção da organização."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fim do intervalo (ISO 8601). Padrão: agora."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de mensagens.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da mensagem no Messajo (`msg_…`).",
                            "examples": [
                              "msg_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID da mensagem na Meta; `null` antes do aceite."
                          },
                          "direction": {
                            "enum": [
                              "inbound",
                              "outbound"
                            ],
                            "type": "string",
                            "description": "Direção: `inbound` (recebida) ou `outbound` (enviada)."
                          },
                          "source": {
                            "enum": [
                              "customer",
                              "api",
                              "business_app",
                              "history",
                              "campaign"
                            ],
                            "type": "string",
                            "description": "Origem: `customer`, `api`, `business_app`, `history` ou `campaign`."
                          },
                          "timestamp": {
                            "type": "string",
                            "description": "Quando a mensagem aconteceu (ISO 8601, UTC)."
                          },
                          "content": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "text"
                                  },
                                  "body": {
                                    "type": "string"
                                  },
                                  "quick_replies": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "title": {
                                          "type": "string"
                                        },
                                        "payload": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "title",
                                        "payload"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "body"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "enum": [
                                      "image",
                                      "video",
                                      "document"
                                    ]
                                  },
                                  "media": {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "mime_type": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "sha256": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "size_bytes": {
                                        "anyOf": [
                                          {
                                            "type": "integer",
                                            "minimum": 0,
                                            "maximum": 9007199254740991
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "filename": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "caption": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "status": {
                                        "enum": [
                                          "pending",
                                          "stored",
                                          "failed"
                                        ],
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "id",
                                      "mime_type",
                                      "sha256",
                                      "size_bytes",
                                      "filename",
                                      "caption",
                                      "status"
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "media"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "audio"
                                  },
                                  "media": {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "mime_type": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "sha256": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "size_bytes": {
                                        "anyOf": [
                                          {
                                            "type": "integer",
                                            "minimum": 0,
                                            "maximum": 9007199254740991
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "filename": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "caption": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "status": {
                                        "enum": [
                                          "pending",
                                          "stored",
                                          "failed"
                                        ],
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "id",
                                      "mime_type",
                                      "sha256",
                                      "size_bytes",
                                      "filename",
                                      "caption",
                                      "status"
                                    ]
                                  },
                                  "voice": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "type",
                                  "media",
                                  "voice"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "images"
                                  },
                                  "images": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "id": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "mime_type": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "sha256": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "size_bytes": {
                                          "anyOf": [
                                            {
                                              "type": "integer",
                                              "minimum": 0,
                                              "maximum": 9007199254740991
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "filename": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "caption": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "status": {
                                          "enum": [
                                            "pending",
                                            "stored",
                                            "failed"
                                          ],
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "id",
                                        "mime_type",
                                        "sha256",
                                        "size_bytes",
                                        "filename",
                                        "caption",
                                        "status"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "images"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "like"
                                  }
                                },
                                "required": [
                                  "type"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "sticker"
                                  },
                                  "media": {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "mime_type": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "sha256": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "size_bytes": {
                                        "anyOf": [
                                          {
                                            "type": "integer",
                                            "minimum": 0,
                                            "maximum": 9007199254740991
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "filename": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "caption": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "status": {
                                        "enum": [
                                          "pending",
                                          "stored",
                                          "failed"
                                        ],
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "id",
                                      "mime_type",
                                      "sha256",
                                      "size_bytes",
                                      "filename",
                                      "caption",
                                      "status"
                                    ]
                                  },
                                  "animated": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "type",
                                  "media",
                                  "animated"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "location"
                                  },
                                  "latitude": {
                                    "type": "number"
                                  },
                                  "longitude": {
                                    "type": "number"
                                  },
                                  "name": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "address": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "url": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "latitude",
                                  "longitude",
                                  "name",
                                  "address",
                                  "url"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "contacts"
                                  },
                                  "contacts": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "name": {
                                          "type": "object",
                                          "properties": {
                                            "formatted_name": {
                                              "type": "string"
                                            },
                                            "first_name": {
                                              "anyOf": [
                                                {
                                                  "type": "string"
                                                },
                                                {
                                                  "type": "null"
                                                }
                                              ]
                                            },
                                            "last_name": {
                                              "anyOf": [
                                                {
                                                  "type": "string"
                                                },
                                                {
                                                  "type": "null"
                                                }
                                              ]
                                            }
                                          },
                                          "required": [
                                            "formatted_name",
                                            "first_name",
                                            "last_name"
                                          ]
                                        },
                                        "phones": {
                                          "type": "array",
                                          "items": {
                                            "type": "object",
                                            "properties": {
                                              "phone": {
                                                "type": "string"
                                              },
                                              "wa_id": {
                                                "anyOf": [
                                                  {
                                                    "type": "string"
                                                  },
                                                  {
                                                    "type": "null"
                                                  }
                                                ]
                                              },
                                              "type": {
                                                "anyOf": [
                                                  {
                                                    "type": "string"
                                                  },
                                                  {
                                                    "type": "null"
                                                  }
                                                ]
                                              }
                                            },
                                            "required": [
                                              "phone",
                                              "wa_id",
                                              "type"
                                            ]
                                          }
                                        },
                                        "emails": {
                                          "type": "array",
                                          "items": {
                                            "type": "object",
                                            "properties": {
                                              "email": {
                                                "type": "string"
                                              },
                                              "type": {
                                                "anyOf": [
                                                  {
                                                    "type": "string"
                                                  },
                                                  {
                                                    "type": "null"
                                                  }
                                                ]
                                              }
                                            },
                                            "required": [
                                              "email",
                                              "type"
                                            ]
                                          }
                                        }
                                      },
                                      "required": [
                                        "name",
                                        "phones",
                                        "emails"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "contacts"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "reaction"
                                  },
                                  "message_id": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "external_message_id": {
                                    "type": "string"
                                  },
                                  "emoji": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "message_id",
                                  "external_message_id",
                                  "emoji"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "reply"
                                  },
                                  "kind": {
                                    "enum": [
                                      "button",
                                      "list",
                                      "quick_reply",
                                      "postback",
                                      "flow"
                                    ],
                                    "type": "string"
                                  },
                                  "id": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "title": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "description": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "payload": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "kind",
                                  "id",
                                  "title",
                                  "description",
                                  "payload"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "order"
                                  },
                                  "catalog_id": {
                                    "type": "string"
                                  },
                                  "items": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "product_retailer_id": {
                                          "type": "string"
                                        },
                                        "quantity": {
                                          "type": "integer",
                                          "minimum": -9007199254740991,
                                          "maximum": 9007199254740991,
                                          "exclusiveMinimum": 0
                                        },
                                        "item_price": {
                                          "type": "number",
                                          "minimum": 0
                                        },
                                        "currency": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "product_retailer_id",
                                        "quantity",
                                        "item_price",
                                        "currency"
                                      ]
                                    }
                                  },
                                  "note": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "catalog_id",
                                  "items",
                                  "note"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "call_permission_reply"
                                  },
                                  "response": {
                                    "enum": [
                                      "accept",
                                      "reject"
                                    ],
                                    "type": "string"
                                  },
                                  "permanent": {
                                    "type": "boolean"
                                  },
                                  "expires_at": {
                                    "anyOf": [
                                      {
                                        "type": "string",
                                        "format": "date-time"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "source": {
                                    "enum": [
                                      "user_action",
                                      "automatic"
                                    ],
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "type",
                                  "response",
                                  "permanent",
                                  "expires_at",
                                  "source"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "share"
                                  },
                                  "kind": {
                                    "enum": [
                                      "post",
                                      "reel",
                                      "story",
                                      "story_mention",
                                      "link"
                                    ],
                                    "type": "string"
                                  },
                                  "url": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "external_id": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "kind",
                                  "url",
                                  "external_id"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "system"
                                  },
                                  "kind": {
                                    "type": "string"
                                  },
                                  "body": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  }
                                },
                                "required": [
                                  "type",
                                  "kind",
                                  "body"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "unsupported"
                                  },
                                  "meta_type": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "type",
                                  "meta_type"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "template"
                                  },
                                  "name": {
                                    "type": "string"
                                  },
                                  "language": {
                                    "type": "string"
                                  },
                                  "components": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "propertyNames": {
                                        "type": "string"
                                      },
                                      "additionalProperties": {}
                                    }
                                  },
                                  "otp": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "type",
                                  "name",
                                  "language",
                                  "components"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "interactive"
                                  },
                                  "kind": {
                                    "enum": [
                                      "button",
                                      "list",
                                      "cta_url",
                                      "location_request",
                                      "flow",
                                      "product",
                                      "product_list",
                                      "catalog_message",
                                      "order_details",
                                      "order_status",
                                      "call_permission_request"
                                    ],
                                    "type": "string"
                                  },
                                  "body": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "interactive": {
                                    "type": "object",
                                    "propertyNames": {
                                      "type": "string"
                                    },
                                    "additionalProperties": {}
                                  }
                                },
                                "required": [
                                  "type",
                                  "kind",
                                  "body",
                                  "interactive"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "buttons"
                                  },
                                  "body": {
                                    "type": "string"
                                  },
                                  "buttons": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                      "anyOf": [
                                        {
                                          "type": "object",
                                          "properties": {
                                            "type": {
                                              "const": "postback"
                                            },
                                            "title": {
                                              "type": "string"
                                            },
                                            "payload": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "type",
                                            "title",
                                            "payload"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "type": {
                                              "const": "web_url"
                                            },
                                            "title": {
                                              "type": "string"
                                            },
                                            "url": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "type",
                                            "title",
                                            "url"
                                          ]
                                        }
                                      ]
                                    }
                                  },
                                  "quick_replies": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "title": {
                                          "type": "string"
                                        },
                                        "payload": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "title",
                                        "payload"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "body",
                                  "buttons"
                                ]
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "type": {
                                    "const": "cards"
                                  },
                                  "cards": {
                                    "type": "array",
                                    "minItems": 1,
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "title": {
                                          "type": "string"
                                        },
                                        "subtitle": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "image_url": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "default_url": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "buttons": {
                                          "type": "array",
                                          "items": {
                                            "anyOf": [
                                              {
                                                "type": "object",
                                                "properties": {
                                                  "type": {
                                                    "const": "postback"
                                                  },
                                                  "title": {
                                                    "type": "string"
                                                  },
                                                  "payload": {
                                                    "type": "string"
                                                  }
                                                },
                                                "required": [
                                                  "type",
                                                  "title",
                                                  "payload"
                                                ]
                                              },
                                              {
                                                "type": "object",
                                                "properties": {
                                                  "type": {
                                                    "const": "web_url"
                                                  },
                                                  "title": {
                                                    "type": "string"
                                                  },
                                                  "url": {
                                                    "type": "string"
                                                  }
                                                },
                                                "required": [
                                                  "type",
                                                  "title",
                                                  "url"
                                                ]
                                              }
                                            ]
                                          }
                                        }
                                      },
                                      "required": [
                                        "title",
                                        "subtitle",
                                        "image_url",
                                        "default_url",
                                        "buttons"
                                      ]
                                    }
                                  },
                                  "quick_replies": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "title": {
                                          "type": "string"
                                        },
                                        "payload": {
                                          "type": "string"
                                        }
                                      },
                                      "required": [
                                        "title",
                                        "payload"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "type",
                                  "cards"
                                ]
                              }
                            ],
                            "description": "Conteúdo normalizado (o mesmo dos eventos `message.*`)."
                          },
                          "context": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "reply_to": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "message_id": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "external_id": {
                                            "type": "string"
                                          }
                                        },
                                        "required": [
                                          "message_id",
                                          "external_id"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "forwarded": {
                                    "type": "boolean"
                                  },
                                  "frequently_forwarded": {
                                    "type": "boolean"
                                  },
                                  "referral": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "source_type": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "source_id": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "source_url": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "headline": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          },
                                          "ctwa_clid": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          }
                                        },
                                        "required": [
                                          "source_type",
                                          "source_id",
                                          "source_url",
                                          "headline",
                                          "ctwa_clid"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "reply_to_story": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "external_id": {
                                            "type": "string"
                                          },
                                          "url": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ]
                                          }
                                        },
                                        "required": [
                                          "external_id",
                                          "url"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "standby": {
                                    "type": "boolean"
                                  }
                                },
                                "required": [
                                  "reply_to",
                                  "forwarded",
                                  "frequently_forwarded",
                                  "referral"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Contexto: resposta, encaminhamento, anúncio de origem; `null` = sem contexto."
                          },
                          "conversation_id": {
                            "type": "string",
                            "description": "ID da conversa."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID do contato."
                          },
                          "status": {
                            "enum": [
                              "received",
                              "queued",
                              "sent",
                              "delivered",
                              "read",
                              "played",
                              "failed",
                              "deleted"
                            ],
                            "type": "string",
                            "description": "Status da mensagem."
                          },
                          "sent_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Enviada (ISO 8601, UTC)."
                          },
                          "delivered_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Entregue (ISO 8601, UTC)."
                          },
                          "read_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Lida (ISO 8601, UTC)."
                          },
                          "failed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Falhou (ISO 8601, UTC)."
                          },
                          "edited_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Editada (ISO 8601, UTC)."
                          },
                          "revoked_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Apagada pelo remetente (ISO 8601, UTC)."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Erro do envio, no formato da Meta; `null` = sem erro."
                          },
                          "campaign": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "description": "Só mensagens desta campanha."
                                  },
                                  "recipient_id": {
                                    "type": "string",
                                    "description": "ID do destinatário da campanha."
                                  }
                                },
                                "required": [
                                  "id",
                                  "recipient_id"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Campanha que enviou a mensagem; `null` fora de campanha."
                          }
                        },
                        "required": [
                          "id",
                          "external_id",
                          "direction",
                          "source",
                          "timestamp",
                          "content",
                          "context",
                          "conversation_id",
                          "contact_id",
                          "status",
                          "sent_at",
                          "delivered_at",
                          "read_at",
                          "failed_at",
                          "edited_at",
                          "revoked_at",
                          "error",
                          "campaign"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/messages/{id}": {
      "get": {
        "operationId": "getMessage",
        "summary": "Obter mensagem",
        "description": "Retorna uma mensagem dentro da retenção da organização. A mídia aparece com `id`; o conteúdo sai em `GET /v1/media/{id}/content`. Permissão: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da mensagem no Messajo (`msg_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A mensagem.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da mensagem no Messajo (`msg_…`).",
                      "examples": [
                        "msg_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da mensagem na Meta; `null` antes do aceite."
                    },
                    "direction": {
                      "enum": [
                        "inbound",
                        "outbound"
                      ],
                      "type": "string",
                      "description": "Direção: `inbound` (recebida) ou `outbound` (enviada)."
                    },
                    "source": {
                      "enum": [
                        "customer",
                        "api",
                        "business_app",
                        "history",
                        "campaign"
                      ],
                      "type": "string",
                      "description": "Origem: `customer`, `api`, `business_app`, `history` ou `campaign`."
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "Quando a mensagem aconteceu (ISO 8601, UTC)."
                    },
                    "content": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "text"
                            },
                            "body": {
                              "type": "string"
                            },
                            "quick_replies": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "payload": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "title",
                                  "payload"
                                ]
                              }
                            }
                          },
                          "required": [
                            "type",
                            "body"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "enum": [
                                "image",
                                "video",
                                "document"
                              ]
                            },
                            "media": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "mime_type": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "sha256": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "size_bytes": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 9007199254740991
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "filename": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "caption": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "status": {
                                  "enum": [
                                    "pending",
                                    "stored",
                                    "failed"
                                  ],
                                  "type": "string"
                                }
                              },
                              "required": [
                                "id",
                                "mime_type",
                                "sha256",
                                "size_bytes",
                                "filename",
                                "caption",
                                "status"
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "media"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "audio"
                            },
                            "media": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "mime_type": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "sha256": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "size_bytes": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 9007199254740991
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "filename": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "caption": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "status": {
                                  "enum": [
                                    "pending",
                                    "stored",
                                    "failed"
                                  ],
                                  "type": "string"
                                }
                              },
                              "required": [
                                "id",
                                "mime_type",
                                "sha256",
                                "size_bytes",
                                "filename",
                                "caption",
                                "status"
                              ]
                            },
                            "voice": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "type",
                            "media",
                            "voice"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "images"
                            },
                            "images": {
                              "type": "array",
                              "minItems": 1,
                              "items": {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "mime_type": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "sha256": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "size_bytes": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": 0,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "filename": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "caption": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "status": {
                                    "enum": [
                                      "pending",
                                      "stored",
                                      "failed"
                                    ],
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "id",
                                  "mime_type",
                                  "sha256",
                                  "size_bytes",
                                  "filename",
                                  "caption",
                                  "status"
                                ]
                              }
                            }
                          },
                          "required": [
                            "type",
                            "images"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "like"
                            }
                          },
                          "required": [
                            "type"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "sticker"
                            },
                            "media": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "mime_type": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "sha256": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "size_bytes": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": 0,
                                      "maximum": 9007199254740991
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "filename": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "caption": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "status": {
                                  "enum": [
                                    "pending",
                                    "stored",
                                    "failed"
                                  ],
                                  "type": "string"
                                }
                              },
                              "required": [
                                "id",
                                "mime_type",
                                "sha256",
                                "size_bytes",
                                "filename",
                                "caption",
                                "status"
                              ]
                            },
                            "animated": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "type",
                            "media",
                            "animated"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "location"
                            },
                            "latitude": {
                              "type": "number"
                            },
                            "longitude": {
                              "type": "number"
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "address": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "url": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "latitude",
                            "longitude",
                            "name",
                            "address",
                            "url"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "contacts"
                            },
                            "contacts": {
                              "type": "array",
                              "minItems": 1,
                              "items": {
                                "type": "object",
                                "properties": {
                                  "name": {
                                    "type": "object",
                                    "properties": {
                                      "formatted_name": {
                                        "type": "string"
                                      },
                                      "first_name": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      },
                                      "last_name": {
                                        "anyOf": [
                                          {
                                            "type": "string"
                                          },
                                          {
                                            "type": "null"
                                          }
                                        ]
                                      }
                                    },
                                    "required": [
                                      "formatted_name",
                                      "first_name",
                                      "last_name"
                                    ]
                                  },
                                  "phones": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "phone": {
                                          "type": "string"
                                        },
                                        "wa_id": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        },
                                        "type": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        }
                                      },
                                      "required": [
                                        "phone",
                                        "wa_id",
                                        "type"
                                      ]
                                    }
                                  },
                                  "emails": {
                                    "type": "array",
                                    "items": {
                                      "type": "object",
                                      "properties": {
                                        "email": {
                                          "type": "string"
                                        },
                                        "type": {
                                          "anyOf": [
                                            {
                                              "type": "string"
                                            },
                                            {
                                              "type": "null"
                                            }
                                          ]
                                        }
                                      },
                                      "required": [
                                        "email",
                                        "type"
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "name",
                                  "phones",
                                  "emails"
                                ]
                              }
                            }
                          },
                          "required": [
                            "type",
                            "contacts"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "reaction"
                            },
                            "message_id": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "external_message_id": {
                              "type": "string"
                            },
                            "emoji": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "message_id",
                            "external_message_id",
                            "emoji"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "reply"
                            },
                            "kind": {
                              "enum": [
                                "button",
                                "list",
                                "quick_reply",
                                "postback",
                                "flow"
                              ],
                              "type": "string"
                            },
                            "id": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "title": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "description": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "payload": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "kind",
                            "id",
                            "title",
                            "description",
                            "payload"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "order"
                            },
                            "catalog_id": {
                              "type": "string"
                            },
                            "items": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "product_retailer_id": {
                                    "type": "string"
                                  },
                                  "quantity": {
                                    "type": "integer",
                                    "minimum": -9007199254740991,
                                    "maximum": 9007199254740991,
                                    "exclusiveMinimum": 0
                                  },
                                  "item_price": {
                                    "type": "number",
                                    "minimum": 0
                                  },
                                  "currency": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "product_retailer_id",
                                  "quantity",
                                  "item_price",
                                  "currency"
                                ]
                              }
                            },
                            "note": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "catalog_id",
                            "items",
                            "note"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "call_permission_reply"
                            },
                            "response": {
                              "enum": [
                                "accept",
                                "reject"
                              ],
                              "type": "string"
                            },
                            "permanent": {
                              "type": "boolean"
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string",
                                  "format": "date-time"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "source": {
                              "enum": [
                                "user_action",
                                "automatic"
                              ],
                              "type": "string"
                            }
                          },
                          "required": [
                            "type",
                            "response",
                            "permanent",
                            "expires_at",
                            "source"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "share"
                            },
                            "kind": {
                              "enum": [
                                "post",
                                "reel",
                                "story",
                                "story_mention",
                                "link"
                              ],
                              "type": "string"
                            },
                            "url": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "external_id": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "kind",
                            "url",
                            "external_id"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "system"
                            },
                            "kind": {
                              "type": "string"
                            },
                            "body": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "kind",
                            "body"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "unsupported"
                            },
                            "meta_type": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "type",
                            "meta_type"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "template"
                            },
                            "name": {
                              "type": "string"
                            },
                            "language": {
                              "type": "string"
                            },
                            "components": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              }
                            },
                            "otp": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "type",
                            "name",
                            "language",
                            "components"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "interactive"
                            },
                            "kind": {
                              "enum": [
                                "button",
                                "list",
                                "cta_url",
                                "location_request",
                                "flow",
                                "product",
                                "product_list",
                                "catalog_message",
                                "order_details",
                                "order_status",
                                "call_permission_request"
                              ],
                              "type": "string"
                            },
                            "body": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "interactive": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            }
                          },
                          "required": [
                            "type",
                            "kind",
                            "body",
                            "interactive"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "buttons"
                            },
                            "body": {
                              "type": "string"
                            },
                            "buttons": {
                              "type": "array",
                              "minItems": 1,
                              "items": {
                                "anyOf": [
                                  {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "const": "postback"
                                      },
                                      "title": {
                                        "type": "string"
                                      },
                                      "payload": {
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "type",
                                      "title",
                                      "payload"
                                    ]
                                  },
                                  {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "const": "web_url"
                                      },
                                      "title": {
                                        "type": "string"
                                      },
                                      "url": {
                                        "type": "string"
                                      }
                                    },
                                    "required": [
                                      "type",
                                      "title",
                                      "url"
                                    ]
                                  }
                                ]
                              }
                            },
                            "quick_replies": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "payload": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "title",
                                  "payload"
                                ]
                              }
                            }
                          },
                          "required": [
                            "type",
                            "body",
                            "buttons"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "const": "cards"
                            },
                            "cards": {
                              "type": "array",
                              "minItems": 1,
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "subtitle": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "image_url": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "default_url": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "buttons": {
                                    "type": "array",
                                    "items": {
                                      "anyOf": [
                                        {
                                          "type": "object",
                                          "properties": {
                                            "type": {
                                              "const": "postback"
                                            },
                                            "title": {
                                              "type": "string"
                                            },
                                            "payload": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "type",
                                            "title",
                                            "payload"
                                          ]
                                        },
                                        {
                                          "type": "object",
                                          "properties": {
                                            "type": {
                                              "const": "web_url"
                                            },
                                            "title": {
                                              "type": "string"
                                            },
                                            "url": {
                                              "type": "string"
                                            }
                                          },
                                          "required": [
                                            "type",
                                            "title",
                                            "url"
                                          ]
                                        }
                                      ]
                                    }
                                  }
                                },
                                "required": [
                                  "title",
                                  "subtitle",
                                  "image_url",
                                  "default_url",
                                  "buttons"
                                ]
                              }
                            },
                            "quick_replies": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "title": {
                                    "type": "string"
                                  },
                                  "payload": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "title",
                                  "payload"
                                ]
                              }
                            }
                          },
                          "required": [
                            "type",
                            "cards"
                          ]
                        }
                      ],
                      "description": "Conteúdo normalizado (o mesmo dos eventos `message.*`)."
                    },
                    "context": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "reply_to": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "message_id": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ]
                                    },
                                    "external_id": {
                                      "type": "string"
                                    }
                                  },
                                  "required": [
                                    "message_id",
                                    "external_id"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "forwarded": {
                              "type": "boolean"
                            },
                            "frequently_forwarded": {
                              "type": "boolean"
                            },
                            "referral": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "source_type": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ]
                                    },
                                    "source_id": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ]
                                    },
                                    "source_url": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ]
                                    },
                                    "headline": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ]
                                    },
                                    "ctwa_clid": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ]
                                    }
                                  },
                                  "required": [
                                    "source_type",
                                    "source_id",
                                    "source_url",
                                    "headline",
                                    "ctwa_clid"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "reply_to_story": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "external_id": {
                                      "type": "string"
                                    },
                                    "url": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ]
                                    }
                                  },
                                  "required": [
                                    "external_id",
                                    "url"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ]
                            },
                            "standby": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "reply_to",
                            "forwarded",
                            "frequently_forwarded",
                            "referral"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contexto: resposta, encaminhamento, anúncio de origem; `null` = sem contexto."
                    },
                    "conversation_id": {
                      "type": "string",
                      "description": "ID da conversa."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do contato."
                    },
                    "status": {
                      "enum": [
                        "received",
                        "queued",
                        "sent",
                        "delivered",
                        "read",
                        "played",
                        "failed",
                        "deleted"
                      ],
                      "type": "string",
                      "description": "Status da mensagem."
                    },
                    "sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enviada (ISO 8601, UTC)."
                    },
                    "delivered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Entregue (ISO 8601, UTC)."
                    },
                    "read_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Lida (ISO 8601, UTC)."
                    },
                    "failed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Falhou (ISO 8601, UTC)."
                    },
                    "edited_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Editada (ISO 8601, UTC)."
                    },
                    "revoked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Apagada pelo remetente (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erro do envio, no formato da Meta; `null` = sem erro."
                    },
                    "campaign": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "description": "Só mensagens desta campanha."
                            },
                            "recipient_id": {
                              "type": "string",
                              "description": "ID do destinatário da campanha."
                            }
                          },
                          "required": [
                            "id",
                            "recipient_id"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Campanha que enviou a mensagem; `null` fora de campanha."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "direction",
                    "source",
                    "timestamp",
                    "content",
                    "context",
                    "conversation_id",
                    "contact_id",
                    "status",
                    "sent_at",
                    "delivered_at",
                    "read_at",
                    "failed_at",
                    "edited_at",
                    "revoked_at",
                    "error",
                    "campaign"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/contacts": {
      "get": {
        "operationId": "listContacts",
        "summary": "Listar contatos",
        "description": "Lista os contatos, do visto mais recentemente para o mais antigo. `identity` busca exata (telefone, BSUID, @usuário, IGSID/PSID); `q` busca pelo começo do nome. Chave presa a conexões vê só contatos com conversa nelas. Permissão: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "Cursor opaco da página seguinte: o `next_cursor` da resposta anterior, com os mesmos filtros. Adulterado ou de outra rota → `400 invalid_cursor`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "channel",
            "in": "query",
            "schema": {
              "enum": [
                "whatsapp",
                "instagram",
                "messenger"
              ],
              "type": "string",
              "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "identity",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "description": "Identidade exata: telefone (só dígitos), BSUID, @usuário, IGSID ou PSID."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "description": "Começo do nome do contato (até 64 caracteres)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Contatos vistos a partir desta data (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de contatos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do contato."
                          },
                          "channel": {
                            "enum": [
                              "whatsapp",
                              "instagram",
                              "messenger"
                            ],
                            "type": "string",
                            "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                          },
                          "display_name": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome do contato, quando conhecido."
                          },
                          "identities": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "description": "Tipo: `wa_id`, `bsuid`, `username`, `igsid` ou `psid`."
                                },
                                "value": {
                                  "type": "string",
                                  "description": "Valor da identidade."
                                },
                                "scope": {
                                  "type": "string",
                                  "description": "Escopo da identidade (ex.: portfólio do BSUID); vazio = global."
                                }
                              },
                              "required": [
                                "kind",
                                "value",
                                "scope"
                              ]
                            },
                            "description": "Identidades do contato no canal."
                          },
                          "first_seen_at": {
                            "type": "string",
                            "description": "Primeira vez que o contato apareceu (ISO 8601, UTC)."
                          },
                          "last_seen_at": {
                            "type": "string",
                            "description": "Última vez que o contato apareceu (ISO 8601, UTC)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Data de criação (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "channel",
                          "display_name",
                          "identities",
                          "first_seen_at",
                          "last_seen_at",
                          "created_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/contacts/{id}": {
      "get": {
        "operationId": "getContact",
        "summary": "Obter contato",
        "description": "Retorna um contato com as identidades dele. Permissão: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do contato."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O contato.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do contato."
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` ou `messenger`."
                    },
                    "display_name": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome do contato, quando conhecido."
                    },
                    "identities": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "description": "Tipo: `wa_id`, `bsuid`, `username`, `igsid` ou `psid`."
                          },
                          "value": {
                            "type": "string",
                            "description": "Valor da identidade."
                          },
                          "scope": {
                            "type": "string",
                            "description": "Escopo da identidade (ex.: portfólio do BSUID); vazio = global."
                          }
                        },
                        "required": [
                          "kind",
                          "value",
                          "scope"
                        ]
                      },
                      "description": "Identidades do contato no canal."
                    },
                    "first_seen_at": {
                      "type": "string",
                      "description": "Primeira vez que o contato apareceu (ISO 8601, UTC)."
                    },
                    "last_seen_at": {
                      "type": "string",
                      "description": "Última vez que o contato apareceu (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "channel",
                    "display_name",
                    "identities",
                    "first_seen_at",
                    "last_seen_at",
                    "created_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns": {
      "get": {
        "operationId": "listCampaigns",
        "summary": "Listar campanhas",
        "description": "Lista as campanhas da organização, da mais nova para a mais antiga. Chave presa a conexões vê só as campanhas delas. Permissão: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de campanhas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da campanha (`cmp_…`).",
                            "examples": [
                              "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "name": {
                            "type": "string",
                            "description": "Nome da campanha."
                          },
                          "status": {
                            "enum": [
                              "draft",
                              "scheduled",
                              "running",
                              "waiting_limit",
                              "paused",
                              "auto_paused",
                              "completed",
                              "canceled"
                            ],
                            "type": "string",
                            "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                          },
                          "template": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "anyOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ],
                                "description": "ID do template no Messajo."
                              },
                              "name": {
                                "type": "string",
                                "description": "Nome do template."
                              },
                              "language": {
                                "type": "string",
                                "description": "Idioma do template, ex.: `pt_BR`."
                              },
                              "category": {
                                "type": "string",
                                "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                              }
                            },
                            "required": [
                              "id",
                              "name",
                              "language",
                              "category"
                            ],
                            "description": "Template da campanha."
                          },
                          "variables": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {},
                            "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                          },
                          "rate_limit_mps": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                          },
                          "effective_rate_mps": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Mensagens por segundo usadas de fato."
                          },
                          "scheduled_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Início agendado (ISO 8601)."
                          },
                          "started_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Início (ISO 8601, UTC)."
                          },
                          "paused_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Pausa (ISO 8601, UTC)."
                          },
                          "pause_reason": {
                            "anyOf": [
                              {
                                "enum": [
                                  "manual",
                                  "quality_low",
                                  "template_paused",
                                  "template_quality_low",
                                  "error_rate",
                                  "marketing_limit",
                                  "policy",
                                  "spam_limit",
                                  "connection_not_active",
                                  "org_suspended",
                                  "spend_cap"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                          },
                          "completed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conclusão (ISO 8601, UTC)."
                          },
                          "canceled_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cancelamento (ISO 8601, UTC)."
                          },
                          "stats": {
                            "type": "object",
                            "properties": {
                              "total": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "pending": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "invalid": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "sending": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "sent": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "delivered": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "read": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "failed": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "unknown": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "skipped": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              "by_error": {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                "description": "Falhas por código de erro."
                              }
                            },
                            "required": [
                              "total",
                              "pending",
                              "invalid",
                              "sending",
                              "sent",
                              "delivered",
                              "read",
                              "failed",
                              "unknown",
                              "skipped",
                              "by_error"
                            ],
                            "description": "Destinatários por status."
                          },
                          "estimate": {
                            "type": "object",
                            "properties": {
                              "recipients_valid": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Destinatários que ainda vão sair."
                              },
                              "effective_rate_mps": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Mensagens por segundo usadas de fato."
                              },
                              "duration_s": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Duração estimada em segundos."
                              },
                              "limit": {
                                "type": "object",
                                "properties": {
                                  "tier": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Teto da faixa; `null` = ilimitado."
                                  },
                                  "used_24h": {
                                    "type": "integer",
                                    "minimum": -9007199254740991,
                                    "maximum": 9007199254740991,
                                    "description": "Destinatários contados nas últimas 24 h."
                                  },
                                  "remaining": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Vagas restantes; `null` = ilimitado."
                                  }
                                },
                                "required": [
                                  "tier",
                                  "used_24h",
                                  "remaining"
                                ],
                                "description": "Faixa de 24 h do portfólio."
                              }
                            },
                            "required": [
                              "recipients_valid",
                              "effective_rate_mps",
                              "duration_s",
                              "limit"
                            ],
                            "description": "Estimativa do envio."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Data de criação (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última alteração (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "status",
                          "connection_id",
                          "template",
                          "variables",
                          "rate_limit_mps",
                          "effective_rate_mps",
                          "scheduled_at",
                          "started_at",
                          "paused_at",
                          "pause_reason",
                          "completed_at",
                          "canceled_at",
                          "stats",
                          "estimate",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createCampaign",
        "summary": "Criar campanha",
        "description": "Cria uma campanha em `draft` para uma conexão do WhatsApp com um template aprovado (`MARKETING` ou `UTILITY`). O mapeamento em `variables` precisa cobrir todo parâmetro do template. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "description": "Nome da campanha."
                  },
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                  },
                  "template_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID do template no Messajo."
                  },
                  "template": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Nome do template."
                      },
                      "language": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Idioma do template, ex.: `pt_BR`."
                      }
                    },
                    "required": [
                      "name",
                      "language"
                    ],
                    "description": "Template por nome e idioma (no lugar de `template_id`)."
                  },
                  "variables": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                  },
                  "rate_limit_mps": {
                    "anyOf": [
                      {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 9007199254740991
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                  }
                },
                "required": [
                  "name",
                  "variables"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A campanha criada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/campaigns/{id}": {
      "get": {
        "operationId": "getCampaign",
        "summary": "Obter campanha",
        "description": "Retorna a campanha com a contagem por status (`stats`) e a estimativa de envio (`estimate`). Permissão: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A campanha.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateCampaign",
        "summary": "Alterar campanha",
        "description": "Template, `variables` e destinatários mudam só em `draft`; `name` e `rate_limit_mps` também em `scheduled`, `paused` e `auto_paused`. Fora disso: `409 campaign_not_editable`. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "description": "Nome da campanha."
                  },
                  "template_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID do template no Messajo."
                  },
                  "template": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Nome do template."
                      },
                      "language": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Idioma do template, ex.: `pt_BR`."
                      }
                    },
                    "required": [
                      "name",
                      "language"
                    ],
                    "description": "Template por nome e idioma (no lugar de `template_id`)."
                  },
                  "variables": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                  },
                  "rate_limit_mps": {
                    "anyOf": [
                      {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 9007199254740991
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A campanha alterada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteCampaign",
        "summary": "Excluir campanha",
        "description": "Exclui a campanha e os destinatários. Só em `draft`, `completed` ou `canceled`. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmação da exclusão.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/recipients": {
      "post": {
        "operationId": "addCampaignRecipients",
        "summary": "Adicionar destinatários",
        "description": "JSON `{ recipients }` (até 10 000 por chamada) grava na hora e devolve a importação concluída (`201`). Multipart com `file` (CSV, JSON ou NDJSON, até 20 MiB) devolve `202` e processa em segundo plano: acompanhe em `GET /v1/campaigns/{id}/imports/{import_id}`. Só em `draft`. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "recipients": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 10000,
                    "items": {
                      "type": "object",
                      "properties": {
                        "to": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Destino: telefone (com DDI), BSUID ou `ctc_…` de um contato."
                        },
                        "variables": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "string",
                            "maxLength": 1024
                          },
                          "description": "Variáveis do destinatário (coluna → valor)."
                        }
                      },
                      "required": [
                        "to"
                      ]
                    },
                    "description": "Destinatários inline (até 10 000)."
                  },
                  "file": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "Arquivo CSV, JSON ou NDJSON (até 20 MiB)."
                  },
                  "to_column": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Coluna do CSV com o destino (padrão `to`)."
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "recipients": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 10000,
                    "items": {
                      "type": "object",
                      "properties": {
                        "to": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Destino: telefone (com DDI), BSUID ou `ctc_…` de um contato."
                        },
                        "variables": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "string",
                            "maxLength": 1024
                          },
                          "description": "Variáveis do destinatário (coluna → valor)."
                        }
                      },
                      "required": [
                        "to"
                      ]
                    },
                    "description": "Destinatários inline (até 10 000)."
                  },
                  "file": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "Arquivo CSV, JSON ou NDJSON (até 20 MiB)."
                  },
                  "to_column": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Coluna do CSV com o destino (padrão `to`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Lista inline gravada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da importação (`cim_…`)."
                    },
                    "campaign_id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`)."
                    },
                    "source": {
                      "enum": [
                        "inline",
                        "csv",
                        "json",
                        "ndjson"
                      ],
                      "type": "string",
                      "description": "Origem: `inline`, `csv`, `json` ou `ndjson`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome do arquivo enviado."
                    },
                    "status": {
                      "enum": [
                        "queued",
                        "processing",
                        "completed",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Status: `queued`, `processing`, `completed` ou `failed`."
                    },
                    "rows_total": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas lidas."
                    },
                    "rows_valid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Destinatários válidos gravados."
                    },
                    "rows_invalid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas inválidas."
                    },
                    "rows_duplicate": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas repetidas (ignoradas)."
                    },
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "row": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "column": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "code": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "row",
                          "column",
                          "code"
                        ]
                      },
                      "description": "Até 100 erros por linha (`row`, `column`, `code`)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "campaign_id",
                    "source",
                    "filename",
                    "status",
                    "rows_total",
                    "rows_valid",
                    "rows_invalid",
                    "rows_duplicate",
                    "errors",
                    "created_at",
                    "started_at",
                    "completed_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "202": {
            "description": "Arquivo recebido; a importação roda em segundo plano.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da importação (`cim_…`)."
                    },
                    "campaign_id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`)."
                    },
                    "source": {
                      "enum": [
                        "inline",
                        "csv",
                        "json",
                        "ndjson"
                      ],
                      "type": "string",
                      "description": "Origem: `inline`, `csv`, `json` ou `ndjson`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome do arquivo enviado."
                    },
                    "status": {
                      "enum": [
                        "queued",
                        "processing",
                        "completed",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Status: `queued`, `processing`, `completed` ou `failed`."
                    },
                    "rows_total": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas lidas."
                    },
                    "rows_valid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Destinatários válidos gravados."
                    },
                    "rows_invalid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas inválidas."
                    },
                    "rows_duplicate": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas repetidas (ignoradas)."
                    },
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "row": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "column": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "code": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "row",
                          "column",
                          "code"
                        ]
                      },
                      "description": "Até 100 erros por linha (`row`, `column`, `code`)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "campaign_id",
                    "source",
                    "filename",
                    "status",
                    "rows_total",
                    "rows_valid",
                    "rows_invalid",
                    "rows_duplicate",
                    "errors",
                    "created_at",
                    "started_at",
                    "completed_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "get": {
        "operationId": "listCampaignRecipients",
        "summary": "Listar destinatários",
        "description": "Lista os destinatários da campanha na ordem de envio, com filtro por status. Permissão: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending",
                "invalid",
                "sending",
                "sent",
                "delivered",
                "read",
                "failed",
                "unknown",
                "skipped"
              ],
              "type": "string",
              "description": "Status do destinatário: `pending`, `invalid`, `sending`, `sent`, `delivered`, `read`, `failed`, `unknown` ou `skipped`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de destinatários.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do destinatário (`crc_…`)."
                          },
                          "seq": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Posição na ordem de envio."
                          },
                          "to_kind": {
                            "enum": [
                              "phone",
                              "bsuid"
                            ],
                            "type": "string",
                            "description": "Tipo do destino: `phone` ou `bsuid`."
                          },
                          "to": {
                            "type": "string",
                            "description": "Destino: telefone (com DDI), BSUID ou `ctc_…` de um contato."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Contato do destinatário, quando conhecido."
                          },
                          "variables": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {
                              "type": "string"
                            },
                            "description": "Variáveis do destinatário (coluna → valor)."
                          },
                          "status": {
                            "enum": [
                              "pending",
                              "invalid",
                              "sending",
                              "sent",
                              "delivered",
                              "read",
                              "failed",
                              "unknown",
                              "skipped"
                            ],
                            "type": "string",
                            "description": "Status do destinatário: `pending`, `invalid`, `sending`, `sent`, `delivered`, `read`, `failed`, `unknown` ou `skipped`."
                          },
                          "invalid_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Por que o destinatário é inválido."
                          },
                          "message_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID da mensagem enviada (`msg_…`)."
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID da mensagem na Meta."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "code": {
                                    "type": "string"
                                  },
                                  "meta_code": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ]
                                  },
                                  "message": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "code",
                                  "meta_code",
                                  "message"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Erro do envio (`code`, `meta_code`, `message`)."
                          },
                          "sent_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Enviada (ISO 8601, UTC)."
                          },
                          "delivered_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Entregue (ISO 8601, UTC)."
                          },
                          "read_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Lida (ISO 8601, UTC)."
                          },
                          "failed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Falhou (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "seq",
                          "to_kind",
                          "to",
                          "contact_id",
                          "variables",
                          "status",
                          "invalid_reason",
                          "message_id",
                          "external_id",
                          "error",
                          "sent_at",
                          "delivered_at",
                          "read_at",
                          "failed_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/imports": {
      "get": {
        "operationId": "listCampaignImports",
        "summary": "Listar importações",
        "description": "Lista as importações de destinatários da campanha, da mais nova para a mais antiga. Permissão: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Uma página de importações.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da importação (`cim_…`)."
                          },
                          "campaign_id": {
                            "type": "string",
                            "description": "ID da campanha (`cmp_…`)."
                          },
                          "source": {
                            "enum": [
                              "inline",
                              "csv",
                              "json",
                              "ndjson"
                            ],
                            "type": "string",
                            "description": "Origem: `inline`, `csv`, `json` ou `ndjson`."
                          },
                          "filename": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome do arquivo enviado."
                          },
                          "status": {
                            "enum": [
                              "queued",
                              "processing",
                              "completed",
                              "failed"
                            ],
                            "type": "string",
                            "description": "Status: `queued`, `processing`, `completed` ou `failed`."
                          },
                          "rows_total": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Linhas lidas."
                          },
                          "rows_valid": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Destinatários válidos gravados."
                          },
                          "rows_invalid": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Linhas inválidas."
                          },
                          "rows_duplicate": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Linhas repetidas (ignoradas)."
                          },
                          "errors": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "row": {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                "column": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "code": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "row",
                                "column",
                                "code"
                              ]
                            },
                            "description": "Até 100 erros por linha (`row`, `column`, `code`)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Data de criação (ISO 8601, UTC)."
                          },
                          "started_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Início (ISO 8601, UTC)."
                          },
                          "completed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conclusão (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "campaign_id",
                          "source",
                          "filename",
                          "status",
                          "rows_total",
                          "rows_valid",
                          "rows_invalid",
                          "rows_duplicate",
                          "errors",
                          "created_at",
                          "started_at",
                          "completed_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/imports/{import_id}": {
      "get": {
        "operationId": "getCampaignImport",
        "summary": "Obter importação",
        "description": "Retorna uma importação com as contagens e até 100 erros por linha. Permissão: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "name": "import_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da importação (`cim_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A importação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da importação (`cim_…`)."
                    },
                    "campaign_id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`)."
                    },
                    "source": {
                      "enum": [
                        "inline",
                        "csv",
                        "json",
                        "ndjson"
                      ],
                      "type": "string",
                      "description": "Origem: `inline`, `csv`, `json` ou `ndjson`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nome do arquivo enviado."
                    },
                    "status": {
                      "enum": [
                        "queued",
                        "processing",
                        "completed",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Status: `queued`, `processing`, `completed` ou `failed`."
                    },
                    "rows_total": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas lidas."
                    },
                    "rows_valid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Destinatários válidos gravados."
                    },
                    "rows_invalid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas inválidas."
                    },
                    "rows_duplicate": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Linhas repetidas (ignoradas)."
                    },
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "row": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "column": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "code": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "row",
                          "column",
                          "code"
                        ]
                      },
                      "description": "Até 100 erros por linha (`row`, `column`, `code`)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "campaign_id",
                    "source",
                    "filename",
                    "status",
                    "rows_total",
                    "rows_valid",
                    "rows_invalid",
                    "rows_duplicate",
                    "errors",
                    "created_at",
                    "started_at",
                    "completed_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/preview": {
      "post": {
        "operationId": "previewCampaign",
        "summary": "Pré-visualizar campanha",
        "description": "Monta a mensagem dos primeiros destinatários válidos com as variáveis trocadas, sem enviar nada. Permissão: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10,
                    "default": 5,
                    "description": "Quantos destinatários pré-visualizar (1 a 10, padrão 5)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "As mensagens montadas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "recipient_id": {
                            "type": "string",
                            "description": "ID do destinatário (`crc_…`)."
                          },
                          "to": {
                            "type": "string",
                            "description": "Destino: telefone (com DDI), BSUID ou `ctc_…` de um contato."
                          },
                          "components": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            "description": "`components` do template, como seguem para a Meta."
                          },
                          "rendered_body": {
                            "type": "string",
                            "description": "Corpo com os parâmetros trocados."
                          }
                        },
                        "required": [
                          "recipient_id",
                          "to",
                          "components",
                          "rendered_body"
                        ]
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/schedule": {
      "post": {
        "operationId": "scheduleCampaign",
        "summary": "Agendar campanha",
        "description": "Agenda o início entre agora + 1 min e agora + 90 dias. Exige ao menos um destinatário válido e nenhuma importação em andamento. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "scheduled_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Início agendado (ISO 8601)."
                  }
                },
                "required": [
                  "scheduled_at"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A campanha agendada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/unschedule": {
      "post": {
        "operationId": "unscheduleCampaign",
        "summary": "Desagendar campanha",
        "description": "Volta a campanha agendada para `draft`. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A campanha em rascunho.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/start": {
      "post": {
        "operationId": "startCampaign",
        "summary": "Iniciar campanha",
        "description": "Inicia o envio agora a partir do `draft`. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A campanha em envio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/pause": {
      "post": {
        "operationId": "pauseCampaign",
        "summary": "Pausar campanha",
        "description": "Pausa o envio; quem já está saindo termina. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A campanha pausada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/resume": {
      "post": {
        "operationId": "resumeCampaign",
        "summary": "Retomar campanha",
        "description": "Retoma uma campanha pausada (pela pessoa ou automaticamente), aceitando a qualidade atual como referência. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A campanha em envio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/cancel": {
      "post": {
        "operationId": "cancelCampaign",
        "summary": "Cancelar campanha",
        "description": "Cancela a campanha; quem ainda não saiu vira `skipped`. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "A campanha cancelada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/duplicate": {
      "post": {
        "operationId": "duplicateCampaign",
        "summary": "Duplicar campanha",
        "description": "Cria um `draft` com o mesmo template, mapeamento e ritmo; `recipients` escolhe quais destinatários copiar. Permissão: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "description": "Nome da campanha."
                  },
                  "recipients": {
                    "enum": [
                      "none",
                      "all",
                      "failed",
                      "unknown_or_failed"
                    ],
                    "type": "string",
                    "default": "none",
                    "description": "Destinatários a copiar: `none`, `all`, `failed` ou `unknown_or_failed`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A campanha nova.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da campanha (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome da campanha."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` ou `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp que envia. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID do template no Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nome do template."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma do template, ex.: `pt_BR`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoria do template: `MARKETING` ou `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Template da campanha."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeamento das variáveis do template: `header`, `body` e `buttons`, cada parâmetro com `column` (coluna da lista), `value` (fixo) ou `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensagens por segundo; `null` = automático (80 % da vazão do número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensagens por segundo usadas de fato."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início agendado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início (ISO 8601, UTC)."
                    },
                    "paused_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Pausa (ISO 8601, UTC)."
                    },
                    "pause_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "manual",
                            "quality_low",
                            "template_paused",
                            "template_quality_low",
                            "error_rate",
                            "marketing_limit",
                            "policy",
                            "spam_limit",
                            "connection_not_active",
                            "org_suspended",
                            "spend_cap"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo da pausa: `manual` ou o motivo da pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conclusão (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelamento (ISO 8601, UTC)."
                    },
                    "stats": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "pending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sending": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "sent": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "delivered": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "read": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "failed": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "unknown": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "skipped": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        "by_error": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991
                          },
                          "description": "Falhas por código de erro."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatários por status."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatários que ainda vão sair."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensagens por segundo usadas de fato."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duração estimada em segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Teto da faixa; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatários contados nas últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Vagas restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Faixa de 24 h do portfólio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimativa do envio."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Data de criação (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração (ISO 8601, UTC)."
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "status",
                    "connection_id",
                    "template",
                    "variables",
                    "rate_limit_mps",
                    "effective_rate_mps",
                    "scheduled_at",
                    "started_at",
                    "paused_at",
                    "pause_reason",
                    "completed_at",
                    "canceled_at",
                    "stats",
                    "estimate",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/campaigns/{id}/report": {
      "get": {
        "operationId": "getCampaignReport",
        "summary": "Baixar relatório",
        "description": "CSV com uma linha por destinatário: status, erro, ids da mensagem, horários e as variáveis. Permissão: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da campanha (`cmp_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O relatório em CSV.",
            "content": {
              "*/*": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "*/*",
                  "description": "Relatório CSV."
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/calls": {
      "get": {
        "operationId": "listCalls",
        "summary": "Listar ligações",
        "description": "Log de ligações da organização, mais recentes primeiro, com filtros por conexão, direção, status, motivo do fim, contato e período. O SDP nunca vem na leitura (só `has_sdp`): ele chega nos eventos `call.*`. Permissão: `read`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "enum": [
                "user_initiated",
                "business_initiated"
              ],
              "type": "string",
              "description": "`user_initiated` (o usuário ligou) ou `business_initiated` (o número ligou)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "offered",
                "pre_accepted",
                "dialing",
                "ringing",
                "accepted",
                "terminating",
                "ended",
                "rejected"
              ],
              "type": "string",
              "description": "Estado da ligação."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "end_reason",
            "in": "query",
            "schema": {
              "enum": [
                "completed",
                "failed",
                "rejected",
                "missed",
                "canceled",
                "unknown"
              ],
              "type": "string",
              "description": "Motivo do fim, quando terminou."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "contact_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Contato da ligação, quando conhecido."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Só ligações criadas a partir desta data (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Só ligações criadas até esta data (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de ligações.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da ligação (`cal_…`).",
                            "examples": [
                              "cal_0193a1b2c3d47e8f"
                            ]
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Contato da ligação, quando conhecido."
                          },
                          "conversation_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conversa da ligação, quando há."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID da ligação na Meta (`wacid.…`)."
                          },
                          "direction": {
                            "enum": [
                              "user_initiated",
                              "business_initiated"
                            ],
                            "type": "string",
                            "description": "`user_initiated` (o usuário ligou) ou `business_initiated` (o número ligou)."
                          },
                          "status": {
                            "enum": [
                              "offered",
                              "pre_accepted",
                              "dialing",
                              "ringing",
                              "accepted",
                              "terminating",
                              "ended",
                              "rejected"
                            ],
                            "type": "string",
                            "description": "Estado da ligação."
                          },
                          "end_reason": {
                            "anyOf": [
                              {
                                "enum": [
                                  "completed",
                                  "failed",
                                  "rejected",
                                  "missed",
                                  "canceled",
                                  "unknown"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo do fim, quando terminou."
                          },
                          "has_sdp": {
                            "type": "boolean",
                            "description": "`true` enquanto o SDP está guardado (é apagado 1 h depois do fim)."
                          },
                          "biz_opaque_callback_data": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                          },
                          "errors": {
                            "anyOf": [
                              {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "propertyNames": {
                                    "type": "string"
                                  },
                                  "additionalProperties": {}
                                }
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Erros que a Meta informou na ligação."
                          },
                          "offered_at": {
                            "type": "string",
                            "description": "Quando a ligação começou a tocar."
                          },
                          "answered_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando foi atendida."
                          },
                          "start_time": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Início da conversa, pela Meta."
                          },
                          "end_time": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Fim da ligação."
                          },
                          "duration_s": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Duração em segundos."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando a linha foi criada."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última alteração."
                          }
                        },
                        "required": [
                          "id",
                          "connection_id",
                          "contact_id",
                          "conversation_id",
                          "external_id",
                          "direction",
                          "status",
                          "end_reason",
                          "has_sdp",
                          "biz_opaque_callback_data",
                          "errors",
                          "offered_at",
                          "answered_at",
                          "start_time",
                          "end_time",
                          "duration_s",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "connectCall",
        "summary": "Ligar para o usuário",
        "description": "Inicia uma ligação para o usuário com a oferta SDP. Exige permissão de chamada do usuário (`call_permission_required` sem ela) e a Calling API ligada no número. Número em coexistência → `422 calling_not_supported_in_coex`. Permissão: `send`.",
        "tags": [
          "calls"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
                  },
                  "to": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Telefone (só dígitos, com DDI) ou BSUID do usuário."
                  },
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP em texto (até 64 KiB, começa com `v=0`). Obrigatório em `pre-accept` e `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                  }
                },
                "required": [
                  "to",
                  "sdp"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A ligação criada, em `dialing`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da ligação (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contato da ligação, quando conhecido."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversa da ligação, quando há."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID da ligação na Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (o usuário ligou) ou `business_initiated` (o número ligou)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado da ligação."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do fim, quando terminou."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` enquanto o SDP está guardado (é apagado 1 h depois do fim)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erros que a Meta informou na ligação."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Quando a ligação começou a tocar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi atendida."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início da conversa, pela Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fim da ligação."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração em segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a linha foi criada."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "contact_id",
                    "conversation_id",
                    "external_id",
                    "direction",
                    "status",
                    "end_reason",
                    "has_sdp",
                    "biz_opaque_callback_data",
                    "errors",
                    "offered_at",
                    "answered_at",
                    "start_time",
                    "end_time",
                    "duration_s",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/calls/{id}": {
      "get": {
        "operationId": "getCall",
        "summary": "Consultar ligação",
        "description": "Uma ligação do log, sem o SDP. Permissão: `read`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da ligação (`cal_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A ligação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da ligação (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contato da ligação, quando conhecido."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversa da ligação, quando há."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID da ligação na Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (o usuário ligou) ou `business_initiated` (o número ligou)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado da ligação."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do fim, quando terminou."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` enquanto o SDP está guardado (é apagado 1 h depois do fim)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erros que a Meta informou na ligação."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Quando a ligação começou a tocar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi atendida."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início da conversa, pela Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fim da ligação."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração em segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a linha foi criada."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "contact_id",
                    "conversation_id",
                    "external_id",
                    "direction",
                    "status",
                    "end_reason",
                    "has_sdp",
                    "biz_opaque_callback_data",
                    "errors",
                    "offered_at",
                    "answered_at",
                    "start_time",
                    "end_time",
                    "duration_s",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/calls/{id}/pre-accept": {
      "post": {
        "operationId": "preAcceptCall",
        "summary": "Pré-aceitar ligação",
        "description": "Manda o SDP de resposta antes de atender, para a mídia conectar mais rápido. O `accept` seguinte precisa do mesmo SDP. Só vale com a ligação `offered`. Permissão: `send`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da ligação (`cal_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP em texto (até 64 KiB, começa com `v=0`). Obrigatório em `pre-accept` e `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A ligação em `pre_accepted`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da ligação (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contato da ligação, quando conhecido."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversa da ligação, quando há."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID da ligação na Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (o usuário ligou) ou `business_initiated` (o número ligou)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado da ligação."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do fim, quando terminou."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` enquanto o SDP está guardado (é apagado 1 h depois do fim)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erros que a Meta informou na ligação."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Quando a ligação começou a tocar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi atendida."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início da conversa, pela Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fim da ligação."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração em segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a linha foi criada."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "contact_id",
                    "conversation_id",
                    "external_id",
                    "direction",
                    "status",
                    "end_reason",
                    "has_sdp",
                    "biz_opaque_callback_data",
                    "errors",
                    "offered_at",
                    "answered_at",
                    "start_time",
                    "end_time",
                    "duration_s",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/calls/{id}/accept": {
      "post": {
        "operationId": "acceptCall",
        "summary": "Atender ligação",
        "description": "Atende a ligação com o SDP de resposta (o mesmo do `pre-accept`, se houve; senão `409 call_sdp_mismatch`). O áudio corre entre a Meta e o seu cliente WebRTC/SIP, nunca pelo Messajo. Permissão: `send`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da ligação (`cal_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP em texto (até 64 KiB, começa com `v=0`). Obrigatório em `pre-accept` e `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A ligação em `accepted`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da ligação (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contato da ligação, quando conhecido."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversa da ligação, quando há."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID da ligação na Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (o usuário ligou) ou `business_initiated` (o número ligou)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado da ligação."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do fim, quando terminou."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` enquanto o SDP está guardado (é apagado 1 h depois do fim)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erros que a Meta informou na ligação."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Quando a ligação começou a tocar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi atendida."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início da conversa, pela Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fim da ligação."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração em segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a linha foi criada."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "contact_id",
                    "conversation_id",
                    "external_id",
                    "direction",
                    "status",
                    "end_reason",
                    "has_sdp",
                    "biz_opaque_callback_data",
                    "errors",
                    "offered_at",
                    "answered_at",
                    "start_time",
                    "end_time",
                    "duration_s",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/calls/{id}/reject": {
      "post": {
        "operationId": "rejectCall",
        "summary": "Recusar ligação",
        "description": "Recusa uma ligação recebida ainda não atendida. Permissão: `send`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da ligação (`cal_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP em texto (até 64 KiB, começa com `v=0`). Obrigatório em `pre-accept` e `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A ligação em `rejected`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da ligação (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contato da ligação, quando conhecido."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversa da ligação, quando há."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID da ligação na Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (o usuário ligou) ou `business_initiated` (o número ligou)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado da ligação."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do fim, quando terminou."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` enquanto o SDP está guardado (é apagado 1 h depois do fim)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erros que a Meta informou na ligação."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Quando a ligação começou a tocar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi atendida."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início da conversa, pela Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fim da ligação."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração em segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a linha foi criada."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "contact_id",
                    "conversation_id",
                    "external_id",
                    "direction",
                    "status",
                    "end_reason",
                    "has_sdp",
                    "biz_opaque_callback_data",
                    "errors",
                    "offered_at",
                    "answered_at",
                    "start_time",
                    "end_time",
                    "duration_s",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/calls/{id}/terminate": {
      "post": {
        "operationId": "terminateCall",
        "summary": "Encerrar ligação",
        "description": "Desliga uma ligação atendida ou em andamento. O `call.ended` chega pelo webhook da Meta, com a duração. Permissão: `send`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da ligação (`cal_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP em texto (até 64 KiB, começa com `v=0`). Obrigatório em `pre-accept` e `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A ligação em `terminating`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID da ligação (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contato da ligação, quando conhecido."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversa da ligação, quando há."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID da ligação na Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (o usuário ligou) ou `business_initiated` (o número ligou)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado da ligação."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo do fim, quando terminou."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` enquanto o SDP está guardado (é apagado 1 h depois do fim)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto seu que a Meta devolve nos webhooks desta ligação."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erros que a Meta informou na ligação."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Quando a ligação começou a tocar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi atendida."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Início da conversa, pela Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fim da ligação."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duração em segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando a linha foi criada."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "contact_id",
                    "conversation_id",
                    "external_id",
                    "direction",
                    "status",
                    "end_reason",
                    "has_sdp",
                    "biz_opaque_callback_data",
                    "errors",
                    "offered_at",
                    "answered_at",
                    "start_time",
                    "end_time",
                    "duration_s",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/call-permissions": {
      "get": {
        "operationId": "getCallPermission",
        "summary": "Consultar permissão de chamada",
        "description": "Pergunta à Meta se o número pode ligar para o usuário agora e quais ações estão liberadas, com os limites. Atualiza o cache local. Permissão: `read`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Telefone (só dígitos, com DDI) ou BSUID do usuário."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Status da permissão e ações possíveis.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "enum": [
                        "no_permission",
                        "temporary",
                        "permanent",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Permissão do usuário: `no_permission`, `temporary`, `permanent` ou `rejected`."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a permissão temporária vence."
                    },
                    "actions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "action_name": {
                            "type": "string",
                            "description": "Nome da ação na Meta (ex.: `start_call`, `send_call_permission_request`)."
                          },
                          "can_perform_action": {
                            "type": "boolean",
                            "description": "Se a ação pode ser feita agora."
                          },
                          "limits": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            "description": "Limites da Meta para a ação, como vieram."
                          }
                        },
                        "required": [
                          "action_name",
                          "can_perform_action",
                          "limits"
                        ]
                      },
                      "description": "Ações sobre a permissão e se podem ser feitas agora."
                    }
                  },
                  "required": [
                    "status",
                    "expires_at",
                    "actions"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/calling-settings": {
      "get": {
        "operationId": "getCallingSettings",
        "summary": "Consultar configurações de ligação",
        "description": "Bloco `calling` das configurações do número: status, ícone, retorno, horário de atendimento e SIP. `include_sip_credentials=true` devolve a senha SIP uma única vez e exige `admin`; ela nunca é gravada. Permissão: `read`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
            }
          },
          {
            "name": "include_sip_credentials",
            "in": "query",
            "schema": {
              "enum": [
                "true",
                "false"
              ],
              "type": "string",
              "description": "`true` devolve a senha SIP (exige `admin`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "As configurações de ligação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "enum": [
                        "ENABLED",
                        "DISABLED"
                      ],
                      "type": "string",
                      "description": "Calling API ligada (`ENABLED`) ou desligada (`DISABLED`) no número."
                    },
                    "call_icon_visibility": {
                      "enum": [
                        "DEFAULT",
                        "DISABLE_ALL"
                      ],
                      "type": "string",
                      "description": "Mostrar (`DEFAULT`) ou esconder (`DISABLE_ALL`) o ícone de ligar no WhatsApp do usuário."
                    },
                    "callback_permission_status": {
                      "enum": [
                        "ENABLED",
                        "DISABLED"
                      ],
                      "type": "string",
                      "description": "Pedir permissão de retorno automaticamente quando o usuário liga."
                    },
                    "call_hours": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "enum": [
                                "ENABLED",
                                "DISABLED"
                              ],
                              "type": "string"
                            },
                            "timezone_id": {
                              "type": "string",
                              "minLength": 1
                            },
                            "weekly_operating_hours": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "day_of_week": {
                                    "enum": [
                                      "MONDAY",
                                      "TUESDAY",
                                      "WEDNESDAY",
                                      "THURSDAY",
                                      "FRIDAY",
                                      "SATURDAY",
                                      "SUNDAY"
                                    ],
                                    "type": "string"
                                  },
                                  "open_time": {
                                    "type": "string",
                                    "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                  },
                                  "close_time": {
                                    "type": "string",
                                    "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                  }
                                },
                                "required": [
                                  "day_of_week",
                                  "open_time",
                                  "close_time"
                                ]
                              }
                            },
                            "holiday_schedule": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "date": {
                                    "type": "string",
                                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                                  },
                                  "start_time": {
                                    "type": "string",
                                    "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                  },
                                  "end_time": {
                                    "type": "string",
                                    "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                  }
                                },
                                "required": [
                                  "date",
                                  "start_time",
                                  "end_time"
                                ]
                              }
                            }
                          },
                          "required": [
                            "status",
                            "timezone_id",
                            "weekly_operating_hours",
                            "holiday_schedule"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horário de atendimento (semana e feriados); `null` = sem horário."
                    },
                    "sip": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "enum": [
                                "ENABLED",
                                "DISABLED"
                              ],
                              "type": "string"
                            },
                            "servers": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "hostname": {
                                    "type": "string",
                                    "minLength": 1,
                                    "maxLength": 253
                                  },
                                  "port": {
                                    "type": "integer",
                                    "minimum": 1,
                                    "maximum": 65535
                                  },
                                  "request_uri_user_params": {
                                    "type": "object",
                                    "propertyNames": {
                                      "type": "string"
                                    },
                                    "additionalProperties": {
                                      "type": "string"
                                    }
                                  },
                                  "sip_user_password": {
                                    "type": "string",
                                    "description": "Senha SIP do servidor; só com `include_sip_credentials=true`, uma vez."
                                  }
                                },
                                "required": [
                                  "hostname",
                                  "port"
                                ]
                              }
                            }
                          },
                          "required": [
                            "status",
                            "servers"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Configuração SIP; `null` = sem SIP."
                    }
                  },
                  "required": [
                    "status",
                    "call_icon_visibility",
                    "callback_permission_status",
                    "call_hours",
                    "sip"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "put": {
        "operationId": "updateCallingSettings",
        "summary": "Alterar configurações de ligação",
        "description": "Atualização parcial do bloco `calling` (ligar a Calling API, horário, ícone, retorno e servidores SIP). O hostname SIP não pode ser IP privado. Fica na auditoria. Permissão: `admin`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão (número) da ligação. Opcional com chave de conexão (usa a conexão da chave)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "enum": [
                      "ENABLED",
                      "DISABLED"
                    ],
                    "type": "string",
                    "description": "Calling API ligada (`ENABLED`) ou desligada (`DISABLED`) no número."
                  },
                  "call_icon_visibility": {
                    "enum": [
                      "DEFAULT",
                      "DISABLE_ALL"
                    ],
                    "type": "string",
                    "description": "Mostrar (`DEFAULT`) ou esconder (`DISABLE_ALL`) o ícone de ligar no WhatsApp do usuário."
                  },
                  "callback_permission_status": {
                    "enum": [
                      "ENABLED",
                      "DISABLED"
                    ],
                    "type": "string",
                    "description": "Pedir permissão de retorno automaticamente quando o usuário liga."
                  },
                  "call_hours": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "status": {
                            "enum": [
                              "ENABLED",
                              "DISABLED"
                            ],
                            "type": "string"
                          },
                          "timezone_id": {
                            "type": "string",
                            "minLength": 1
                          },
                          "weekly_operating_hours": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "day_of_week": {
                                  "enum": [
                                    "MONDAY",
                                    "TUESDAY",
                                    "WEDNESDAY",
                                    "THURSDAY",
                                    "FRIDAY",
                                    "SATURDAY",
                                    "SUNDAY"
                                  ],
                                  "type": "string"
                                },
                                "open_time": {
                                  "type": "string",
                                  "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                },
                                "close_time": {
                                  "type": "string",
                                  "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                }
                              },
                              "required": [
                                "day_of_week",
                                "open_time",
                                "close_time"
                              ]
                            }
                          },
                          "holiday_schedule": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "date": {
                                  "type": "string",
                                  "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                                },
                                "start_time": {
                                  "type": "string",
                                  "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                },
                                "end_time": {
                                  "type": "string",
                                  "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                }
                              },
                              "required": [
                                "date",
                                "start_time",
                                "end_time"
                              ]
                            }
                          }
                        },
                        "required": [
                          "status",
                          "timezone_id",
                          "weekly_operating_hours",
                          "holiday_schedule"
                        ]
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Horário de atendimento (semana e feriados); `null` = sem horário."
                  },
                  "sip": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "status": {
                            "enum": [
                              "ENABLED",
                              "DISABLED"
                            ],
                            "type": "string"
                          },
                          "servers": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "hostname": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 253
                                },
                                "port": {
                                  "type": "integer",
                                  "minimum": 1,
                                  "maximum": 65535
                                },
                                "request_uri_user_params": {
                                  "type": "object",
                                  "propertyNames": {
                                    "type": "string"
                                  },
                                  "additionalProperties": {
                                    "type": "string"
                                  }
                                }
                              },
                              "required": [
                                "hostname",
                                "port"
                              ]
                            }
                          }
                        },
                        "required": [
                          "status",
                          "servers"
                        ]
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Configuração SIP; `null` = sem SIP."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "As configurações depois da mudança.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "enum": [
                        "ENABLED",
                        "DISABLED"
                      ],
                      "type": "string",
                      "description": "Calling API ligada (`ENABLED`) ou desligada (`DISABLED`) no número."
                    },
                    "call_icon_visibility": {
                      "enum": [
                        "DEFAULT",
                        "DISABLE_ALL"
                      ],
                      "type": "string",
                      "description": "Mostrar (`DEFAULT`) ou esconder (`DISABLE_ALL`) o ícone de ligar no WhatsApp do usuário."
                    },
                    "callback_permission_status": {
                      "enum": [
                        "ENABLED",
                        "DISABLED"
                      ],
                      "type": "string",
                      "description": "Pedir permissão de retorno automaticamente quando o usuário liga."
                    },
                    "call_hours": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "enum": [
                                "ENABLED",
                                "DISABLED"
                              ],
                              "type": "string"
                            },
                            "timezone_id": {
                              "type": "string",
                              "minLength": 1
                            },
                            "weekly_operating_hours": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "day_of_week": {
                                    "enum": [
                                      "MONDAY",
                                      "TUESDAY",
                                      "WEDNESDAY",
                                      "THURSDAY",
                                      "FRIDAY",
                                      "SATURDAY",
                                      "SUNDAY"
                                    ],
                                    "type": "string"
                                  },
                                  "open_time": {
                                    "type": "string",
                                    "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                  },
                                  "close_time": {
                                    "type": "string",
                                    "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                  }
                                },
                                "required": [
                                  "day_of_week",
                                  "open_time",
                                  "close_time"
                                ]
                              }
                            },
                            "holiday_schedule": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "date": {
                                    "type": "string",
                                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                                  },
                                  "start_time": {
                                    "type": "string",
                                    "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                  },
                                  "end_time": {
                                    "type": "string",
                                    "pattern": "^([01]\\d|2[0-3])[0-5]\\d$"
                                  }
                                },
                                "required": [
                                  "date",
                                  "start_time",
                                  "end_time"
                                ]
                              }
                            }
                          },
                          "required": [
                            "status",
                            "timezone_id",
                            "weekly_operating_hours",
                            "holiday_schedule"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horário de atendimento (semana e feriados); `null` = sem horário."
                    },
                    "sip": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "status": {
                              "enum": [
                                "ENABLED",
                                "DISABLED"
                              ],
                              "type": "string"
                            },
                            "servers": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "hostname": {
                                    "type": "string",
                                    "minLength": 1,
                                    "maxLength": 253
                                  },
                                  "port": {
                                    "type": "integer",
                                    "minimum": 1,
                                    "maximum": 65535
                                  },
                                  "request_uri_user_params": {
                                    "type": "object",
                                    "propertyNames": {
                                      "type": "string"
                                    },
                                    "additionalProperties": {
                                      "type": "string"
                                    }
                                  },
                                  "sip_user_password": {
                                    "type": "string",
                                    "description": "Senha SIP do servidor; só com `include_sip_credentials=true`, uma vez."
                                  }
                                },
                                "required": [
                                  "hostname",
                                  "port"
                                ]
                              }
                            }
                          },
                          "required": [
                            "status",
                            "servers"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Configuração SIP; `null` = sem SIP."
                    }
                  },
                  "required": [
                    "status",
                    "call_icon_visibility",
                    "callback_permission_status",
                    "call_hours",
                    "sip"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/groups": {
      "post": {
        "operationId": "createGroup",
        "summary": "Criar grupo",
        "description": "Cria um grupo no número. A Meta confirma por webhook: o grupo nasce `creating` e vira `active` (evento `group.created`) ou `failed` (`group.create_failed`). Número em coexistência → `422 group_not_supported`. Permissão: `send`.",
        "tags": [
          "groups"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão (número) dona do grupo. Opcional com chave de conexão (usa a conexão da chave)."
                  },
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Assunto do grupo (até 128 caracteres)."
                  },
                  "description": {
                    "type": "string",
                    "description": "Descrição do grupo (até 2048 caracteres)."
                  },
                  "join_approval_mode": {
                    "enum": [
                      "auto_approve",
                      "approval_required"
                    ],
                    "type": "string",
                    "description": "`auto_approve` (entra direto pelo link) ou `approval_required` (pedido de entrada)."
                  }
                },
                "required": [
                  "subject"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O grupo, em `creating`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo.",
                      "examples": [
                        "grp_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) dona do grupo. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do grupo na Meta; `null` até a confirmação."
                    },
                    "subject": {
                      "type": "string",
                      "description": "Assunto do grupo (até 128 caracteres)."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição do grupo (até 2048 caracteres)."
                    },
                    "join_approval_mode": {
                      "enum": [
                        "auto_approve",
                        "approval_required"
                      ],
                      "type": "string",
                      "description": "`auto_approve` (entra direto pelo link) ou `approval_required` (pedido de entrada)."
                    },
                    "status": {
                      "enum": [
                        "creating",
                        "active",
                        "suspended",
                        "deleting",
                        "deleted",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado do grupo."
                    },
                    "participant_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Total de participantes."
                    },
                    "participants": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "wa_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Telefone do participante no WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID do participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome de usuário do participante, quando há."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando entrou (ou pediu para entrar)."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at"
                        ]
                      },
                      "description": "Participantes (até 8)."
                    },
                    "pending_join_requests": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Pedidos de entrada pendentes."
                    },
                    "failure": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erro da Meta quando a criação falhou."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando o grupo foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "external_id",
                    "subject",
                    "description",
                    "join_approval_mode",
                    "status",
                    "participant_count",
                    "participants",
                    "pending_join_requests",
                    "failure",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      },
      "get": {
        "operationId": "listGroups",
        "summary": "Listar grupos",
        "description": "Grupos da organização, mais recentes primeiro. Permissão: `read`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão (número) dona do grupo. Opcional com chave de conexão (usa a conexão da chave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "creating",
                "active",
                "suspended",
                "deleting",
                "deleted",
                "failed"
              ],
              "type": "string",
              "description": "Estado do grupo."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de grupos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo.",
                            "examples": [
                              "grp_0193a1b2c3d47e8f"
                            ]
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID da conexão (número) dona do grupo. Opcional com chave de conexão (usa a conexão da chave)."
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID do grupo na Meta; `null` até a confirmação."
                          },
                          "subject": {
                            "type": "string",
                            "description": "Assunto do grupo (até 128 caracteres)."
                          },
                          "description": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Descrição do grupo (até 2048 caracteres)."
                          },
                          "join_approval_mode": {
                            "enum": [
                              "auto_approve",
                              "approval_required"
                            ],
                            "type": "string",
                            "description": "`auto_approve` (entra direto pelo link) ou `approval_required` (pedido de entrada)."
                          },
                          "status": {
                            "enum": [
                              "creating",
                              "active",
                              "suspended",
                              "deleting",
                              "deleted",
                              "failed"
                            ],
                            "type": "string",
                            "description": "Estado do grupo."
                          },
                          "participant_count": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Total de participantes."
                          },
                          "participants": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "wa_id": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "Telefone do participante no WhatsApp."
                                },
                                "user_id": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "BSUID do participante."
                                },
                                "username": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "Nome de usuário do participante, quando há."
                                },
                                "joined_at": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "Quando entrou (ou pediu para entrar)."
                                }
                              },
                              "required": [
                                "wa_id",
                                "user_id",
                                "username",
                                "joined_at"
                              ]
                            },
                            "description": "Participantes (até 8)."
                          },
                          "pending_join_requests": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Pedidos de entrada pendentes."
                          },
                          "failure": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Erro da Meta quando a criação falhou."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando o grupo foi criado."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última alteração."
                          }
                        },
                        "required": [
                          "id",
                          "connection_id",
                          "external_id",
                          "subject",
                          "description",
                          "join_approval_mode",
                          "status",
                          "participant_count",
                          "participants",
                          "pending_join_requests",
                          "failure",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/groups/{id}": {
      "get": {
        "operationId": "getGroup",
        "summary": "Consultar grupo",
        "description": "Um grupo com assunto, descrição, participantes e pedidos pendentes. Permissão: `read`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O grupo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo.",
                      "examples": [
                        "grp_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) dona do grupo. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do grupo na Meta; `null` até a confirmação."
                    },
                    "subject": {
                      "type": "string",
                      "description": "Assunto do grupo (até 128 caracteres)."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição do grupo (até 2048 caracteres)."
                    },
                    "join_approval_mode": {
                      "enum": [
                        "auto_approve",
                        "approval_required"
                      ],
                      "type": "string",
                      "description": "`auto_approve` (entra direto pelo link) ou `approval_required` (pedido de entrada)."
                    },
                    "status": {
                      "enum": [
                        "creating",
                        "active",
                        "suspended",
                        "deleting",
                        "deleted",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado do grupo."
                    },
                    "participant_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Total de participantes."
                    },
                    "participants": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "wa_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Telefone do participante no WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID do participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome de usuário do participante, quando há."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando entrou (ou pediu para entrar)."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at"
                        ]
                      },
                      "description": "Participantes (até 8)."
                    },
                    "pending_join_requests": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Pedidos de entrada pendentes."
                    },
                    "failure": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erro da Meta quando a criação falhou."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando o grupo foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "external_id",
                    "subject",
                    "description",
                    "join_approval_mode",
                    "status",
                    "participant_count",
                    "participants",
                    "pending_join_requests",
                    "failure",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateGroup",
        "summary": "Alterar grupo",
        "description": "Muda assunto, descrição ou foto (multipart, campo `picture`: JPEG quadrado de pelo menos 192 px, até 5 MiB). Só com o grupo `active`. Permissão: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Assunto do grupo (até 128 caracteres)."
                  },
                  "description": {
                    "type": "string",
                    "description": "Descrição do grupo (até 2048 caracteres)."
                  },
                  "picture": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "Foto do grupo (JPEG quadrado, ≥ 192 px, ≤ 5 MiB)."
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Assunto do grupo (até 128 caracteres)."
                  },
                  "description": {
                    "type": "string",
                    "description": "Descrição do grupo (até 2048 caracteres)."
                  },
                  "picture": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "Foto do grupo (JPEG quadrado, ≥ 192 px, ≤ 5 MiB)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O grupo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo.",
                      "examples": [
                        "grp_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) dona do grupo. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do grupo na Meta; `null` até a confirmação."
                    },
                    "subject": {
                      "type": "string",
                      "description": "Assunto do grupo (até 128 caracteres)."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição do grupo (até 2048 caracteres)."
                    },
                    "join_approval_mode": {
                      "enum": [
                        "auto_approve",
                        "approval_required"
                      ],
                      "type": "string",
                      "description": "`auto_approve` (entra direto pelo link) ou `approval_required` (pedido de entrada)."
                    },
                    "status": {
                      "enum": [
                        "creating",
                        "active",
                        "suspended",
                        "deleting",
                        "deleted",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado do grupo."
                    },
                    "participant_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Total de participantes."
                    },
                    "participants": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "wa_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Telefone do participante no WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID do participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome de usuário do participante, quando há."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando entrou (ou pediu para entrar)."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at"
                        ]
                      },
                      "description": "Participantes (até 8)."
                    },
                    "pending_join_requests": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Pedidos de entrada pendentes."
                    },
                    "failure": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erro da Meta quando a criação falhou."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando o grupo foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "external_id",
                    "subject",
                    "description",
                    "join_approval_mode",
                    "status",
                    "participant_count",
                    "participants",
                    "pending_join_requests",
                    "failure",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteGroup",
        "summary": "Apagar grupo",
        "description": "Apaga o grupo na Meta e remove todos os participantes. Fica na auditoria. Permissão: `admin`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O grupo, em `deleted`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo.",
                      "examples": [
                        "grp_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão (número) dona do grupo. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do grupo na Meta; `null` até a confirmação."
                    },
                    "subject": {
                      "type": "string",
                      "description": "Assunto do grupo (até 128 caracteres)."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição do grupo (até 2048 caracteres)."
                    },
                    "join_approval_mode": {
                      "enum": [
                        "auto_approve",
                        "approval_required"
                      ],
                      "type": "string",
                      "description": "`auto_approve` (entra direto pelo link) ou `approval_required` (pedido de entrada)."
                    },
                    "status": {
                      "enum": [
                        "creating",
                        "active",
                        "suspended",
                        "deleting",
                        "deleted",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado do grupo."
                    },
                    "participant_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Total de participantes."
                    },
                    "participants": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "wa_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Telefone do participante no WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID do participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome de usuário do participante, quando há."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando entrou (ou pediu para entrar)."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at"
                        ]
                      },
                      "description": "Participantes (até 8)."
                    },
                    "pending_join_requests": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Pedidos de entrada pendentes."
                    },
                    "failure": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Erro da Meta quando a criação falhou."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando o grupo foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "external_id",
                    "subject",
                    "description",
                    "join_approval_mode",
                    "status",
                    "participant_count",
                    "participants",
                    "pending_join_requests",
                    "failure",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/groups/{id}/invite-link": {
      "get": {
        "operationId": "getGroupInviteLink",
        "summary": "Consultar link de convite",
        "description": "Link de convite atual do grupo. Permissão: `read`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O link de convite.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invite_link": {
                      "type": "string",
                      "description": "Link de convite do grupo."
                    }
                  },
                  "required": [
                    "invite_link"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/groups/{id}/invite-link/reset": {
      "post": {
        "operationId": "resetGroupInviteLink",
        "summary": "Trocar link de convite",
        "description": "Gera um link novo; o anterior para de funcionar. Permissão: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O link novo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invite_link": {
                      "type": "string",
                      "description": "Link de convite do grupo."
                    }
                  },
                  "required": [
                    "invite_link"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/groups/{id}/participants/remove": {
      "post": {
        "operationId": "removeGroupParticipants",
        "summary": "Remover participantes",
        "description": "Remove até 8 participantes por chamada, por `wa_id` ou `user_id`. Fica na auditoria. Permissão: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "participants": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 8,
                    "items": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "wa_id": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Telefone do participante no WhatsApp."
                            }
                          },
                          "required": [
                            "wa_id"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "user_id": {
                              "type": "string",
                              "minLength": 1,
                              "description": "BSUID do participante."
                            }
                          },
                          "required": [
                            "user_id"
                          ]
                        }
                      ]
                    },
                    "description": "Participantes a remover: `{ wa_id }` ou `{ user_id }` (até 8)."
                  }
                },
                "required": [
                  "participants"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Quantos foram removidos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
                    },
                    "removed": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Quantos participantes foram removidos."
                    }
                  },
                  "required": [
                    "id",
                    "removed"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/groups/{id}/join-requests": {
      "get": {
        "operationId": "listGroupJoinRequests",
        "summary": "Listar pedidos de entrada",
        "description": "Pedidos pendentes de quem quer entrar no grupo (grupos com aprovação). Permissão: `read`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de pedidos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "wa_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Telefone do participante no WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID do participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome de usuário do participante, quando há."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando entrou (ou pediu para entrar)."
                          },
                          "id": {
                            "type": "string",
                            "description": "ID do pedido de entrada."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at",
                          "id"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/groups/{id}/join-requests/approve": {
      "post": {
        "operationId": "approveGroupJoinRequests",
        "summary": "Aprovar pedidos de entrada",
        "description": "Aprova pedidos de entrada; a Meta decide cada um e os que não deram certo vêm em `failed`. Permissão: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "join_request_ids": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": "IDs dos pedidos de entrada."
                  }
                },
                "required": [
                  "join_request_ids"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pedidos aprovados e os que falharam.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "approved": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Pedidos aprovados."
                    },
                    "failed": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do pedido de entrada."
                          },
                          "reason": {
                            "type": "string",
                            "description": "Motivo da falha."
                          }
                        },
                        "required": [
                          "id",
                          "reason"
                        ]
                      },
                      "description": "Pedidos que a Meta não aceitou, com o motivo."
                    }
                  },
                  "required": [
                    "approved",
                    "failed"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/groups/{id}/join-requests/reject": {
      "post": {
        "operationId": "rejectGroupJoinRequests",
        "summary": "Recusar pedidos de entrada",
        "description": "Recusa pedidos de entrada; os que não deram certo vêm em `failed`. Permissão: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do grupo (`grp_…`); use em `to` do `POST /messages` para mandar mensagem ao grupo."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "join_request_ids": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": "IDs dos pedidos de entrada."
                  }
                },
                "required": [
                  "join_request_ids"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pedidos recusados e os que falharam.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "rejected": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Pedidos recusados."
                    },
                    "failed": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do pedido de entrada."
                          },
                          "reason": {
                            "type": "string",
                            "description": "Motivo da falha."
                          }
                        },
                        "required": [
                          "id",
                          "reason"
                        ]
                      },
                      "description": "Pedidos que a Meta não aceitou, com o motivo."
                    }
                  },
                  "required": [
                    "rejected",
                    "failed"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows": {
      "get": {
        "operationId": "listFlows",
        "summary": "Listar Flows",
        "description": "Flows das contas de mensagens (WABA) da organização, mais recentes primeiro, com filtro por conexão e status. Chave presa a conexões precisa de `connection_id`. Permissão: `read`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "DRAFT",
                "PUBLISHED",
                "DEPRECATED",
                "BLOCKED",
                "THROTTLED"
              ],
              "type": "string",
              "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de Flows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do Flow (`flw_…`).",
                            "examples": [
                              "flw_0193a1b2c3d47e8f"
                            ]
                          },
                          "connection_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                          },
                          "messaging_account_id": {
                            "type": "string",
                            "description": "ID da conta de mensagens (WABA) na Meta."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID do Flow na Meta."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nome do Flow (único na conta)."
                          },
                          "categories": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                          },
                          "status": {
                            "enum": [
                              "DRAFT",
                              "PUBLISHED",
                              "DEPRECATED",
                              "BLOCKED",
                              "THROTTLED"
                            ],
                            "type": "string",
                            "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                          },
                          "json_version": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "`version` do JSON do Flow."
                          },
                          "data_api_version": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "`data_api_version` do JSON (Flows com endpoint)."
                          },
                          "validation_errors": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "error": {
                                  "type": "string"
                                },
                                "error_type": {
                                  "type": "string"
                                },
                                "message": {
                                  "type": "string"
                                },
                                "line_start": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "line_end": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "column_start": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "column_end": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                }
                              },
                              "required": [
                                "error",
                                "error_type",
                                "message",
                                "line_start",
                                "line_end",
                                "column_start",
                                "column_end"
                              ]
                            },
                            "description": "Erros de validação da Meta, com linha e coluna."
                          },
                          "endpoint_mode": {
                            "enum": [
                              "none",
                              "messajo"
                            ],
                            "type": "string",
                            "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                          },
                          "handler": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "url_preview": {
                                    "type": "string",
                                    "description": "Origem da URL do handler."
                                  },
                                  "secret_last4": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "4 últimos caracteres do segredo do handler."
                                  }
                                },
                                "required": [
                                  "url_preview",
                                  "secret_last4"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                          },
                          "health_status": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                          },
                          "preview": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "url": {
                                    "type": "string",
                                    "description": "Link de prévia da Meta."
                                  },
                                  "expires_at": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Quando o link de prévia vence."
                                  }
                                },
                                "required": [
                                  "url",
                                  "expires_at"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última prévia gerada."
                          },
                          "last_synced_at": {
                            "type": "string",
                            "description": "Última leitura na Meta."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando foi criado."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última alteração."
                          }
                        },
                        "required": [
                          "id",
                          "connection_id",
                          "messaging_account_id",
                          "external_id",
                          "name",
                          "categories",
                          "status",
                          "json_version",
                          "data_api_version",
                          "validation_errors",
                          "endpoint_mode",
                          "handler",
                          "health_status",
                          "preview",
                          "last_synced_at",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createFlow",
        "summary": "Criar Flow",
        "description": "Cria o Flow na Meta em `DRAFT`. Com `endpoint`, liga o endpoint de data exchange do Messajo: a Meta chama `/meta/flows/{id}`, o Messajo decifra e repassa o pedido assinado ao seu handler. O `handler_secret` (assinatura `Messajo-Signature`) aparece só nesta resposta. Com `flow_json`, já sobe o JSON; erros da Meta voltam em `validation_errors`. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nome do Flow (único na conta)."
                  },
                  "categories": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "enum": [
                        "SIGN_UP",
                        "SIGN_IN",
                        "APPOINTMENT_BOOKING",
                        "LEAD_GENERATION",
                        "CONTACT_US",
                        "CUSTOMER_SUPPORT",
                        "SURVEY",
                        "OTHER"
                      ],
                      "type": "string"
                    },
                    "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                  },
                  "flow_json": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "O `flow.json` (objeto com `version` e `screens`)."
                  },
                  "endpoint": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "minLength": 1,
                        "description": "URL do handler (`https` público)."
                      },
                      "headers": {
                        "type": "array",
                        "maxItems": 20,
                        "items": {
                          "type": "object",
                          "properties": {
                            "name": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Nome do cabeçalho."
                            },
                            "value": {
                              "type": "string",
                              "description": "Valor do cabeçalho."
                            }
                          },
                          "required": [
                            "name",
                            "value"
                          ]
                        },
                        "description": "Cabeçalhos extras enviados ao handler (até 20)."
                      }
                    },
                    "required": [
                      "url"
                    ],
                    "description": "Handler do cliente: liga o endpoint de data exchange do Messajo."
                  }
                },
                "required": [
                  "name",
                  "categories"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O Flow criado, com o segredo do handler uma vez.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    },
                    "handler_secret": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Segredo do handler (`Messajo-Signature`): aparece só quando é gerado."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at",
                    "handler_secret"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/flows/{id}": {
      "get": {
        "operationId": "getFlow",
        "summary": "Consultar Flow",
        "description": "Um Flow, sem a URL completa nem os cabeçalhos do handler (só a origem e os 4 últimos caracteres do segredo). Permissão: `read`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O Flow.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateFlow",
        "summary": "Alterar Flow",
        "description": "Troca nome, categorias ou o handler (`endpoint`; `null` desliga o endpoint do Messajo). `handler_secret` só vem preenchido quando um segredo novo foi gerado. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nome do Flow (único na conta)."
                  },
                  "categories": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "enum": [
                        "SIGN_UP",
                        "SIGN_IN",
                        "APPOINTMENT_BOOKING",
                        "LEAD_GENERATION",
                        "CONTACT_US",
                        "CUSTOMER_SUPPORT",
                        "SURVEY",
                        "OTHER"
                      ],
                      "type": "string"
                    },
                    "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                  },
                  "endpoint": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "url": {
                            "type": "string",
                            "minLength": 1,
                            "description": "URL do handler (`https` público)."
                          },
                          "headers": {
                            "type": "array",
                            "maxItems": 20,
                            "items": {
                              "type": "object",
                              "properties": {
                                "name": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Nome do cabeçalho."
                                },
                                "value": {
                                  "type": "string",
                                  "description": "Valor do cabeçalho."
                                }
                              },
                              "required": [
                                "name",
                                "value"
                              ]
                            },
                            "description": "Cabeçalhos extras enviados ao handler (até 20)."
                          }
                        },
                        "required": [
                          "url"
                        ],
                        "description": "Handler do cliente: liga o endpoint de data exchange do Messajo."
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O Flow alterado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    },
                    "handler_secret": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Segredo do handler (`Messajo-Signature`): aparece só quando é gerado."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at",
                    "handler_secret"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteFlow",
        "summary": "Apagar Flow",
        "description": "Apaga um Flow em `DRAFT` (a Meta não apaga publicado: use `deprecate`). Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows/{id}/json": {
      "put": {
        "operationId": "uploadFlowJson",
        "summary": "Subir JSON do Flow",
        "description": "O corpo é o `flow.json` cru (até 10 MiB). Só em `DRAFT` (senão `409 flow_not_editable`; publicado → `clone`). Erros da Meta voltam em `422 flow_invalid_json` com linha e coluna em `details`. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {},
                "description": "O `flow.json` (objeto com `version` e `screens`)."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O Flow com o JSON novo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows/{id}/publish": {
      "post": {
        "operationId": "publishFlow",
        "summary": "Publicar Flow",
        "description": "Publica o Flow. Com endpoint do Messajo, exige handler e a chave da conta enviada a um número ativo (`409 flow_key_not_uploaded`); a Meta pinga o endpoint. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O Flow publicado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows/{id}/deprecate": {
      "post": {
        "operationId": "deprecateFlow",
        "summary": "Deprecar Flow",
        "description": "Para de aceitar envios de um Flow publicado. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O Flow deprecado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows/{id}/clone": {
      "post": {
        "operationId": "cloneFlow",
        "summary": "Clonar Flow",
        "description": "Cria um `DRAFT` com o mesmo JSON e handler, e segredo novo (aparece só nesta resposta). É assim que se edita um Flow publicado. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nome do Flow (único na conta)."
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O clone, com o segredo do handler uma vez.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    },
                    "handler_secret": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Segredo do handler (`Messajo-Signature`): aparece só quando é gerado."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at",
                    "handler_secret"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows/{id}/preview": {
      "post": {
        "operationId": "previewFlow",
        "summary": "Pré-visualizar Flow",
        "description": "Link de prévia da Meta, com validade. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Link e validade.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "preview_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Link de prévia da Meta."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando o link de prévia vence."
                    }
                  },
                  "required": [
                    "preview_url",
                    "expires_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows/{id}/rotate-handler-secret": {
      "post": {
        "operationId": "rotateFlowHandlerSecret",
        "summary": "Trocar segredo do handler",
        "description": "Gera um segredo novo para assinar os pedidos ao handler (aparece só nesta resposta); o anterior para de valer na hora. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O Flow, com o segredo novo uma vez.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    },
                    "handler_secret": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Segredo do handler (`Messajo-Signature`): aparece só quando é gerado."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at",
                    "handler_secret"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows/{id}/sync": {
      "post": {
        "operationId": "syncFlow",
        "summary": "Sincronizar Flow",
        "description": "Relê da Meta os Flows da conta (WABA) do Flow: status e erros de validação. Permissão: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O Flow atualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID da conta de mensagens (WABA) na Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do Flow na Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome do Flow (único na conta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorias da Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` ou `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` do JSON do Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` do JSON (Flows com endpoint)."
                    },
                    "validation_errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "error": {
                            "type": "string"
                          },
                          "error_type": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "line_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "line_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_start": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "column_end": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        },
                        "required": [
                          "error",
                          "error_type",
                          "message",
                          "line_start",
                          "line_end",
                          "column_start",
                          "column_end"
                        ]
                      },
                      "description": "Erros de validação da Meta, com linha e coluna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sem endpoint) ou `messajo` (endpoint de data exchange do Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origem da URL do handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres do segredo do handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler do cliente, sem URL completa nem cabeçalhos."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saúde do endpoint segundo a Meta (e alertas do webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Link de prévia da Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Quando o link de prévia vence."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última prévia gerada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Quando foi criado."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Última alteração."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "messaging_account_id",
                    "external_id",
                    "name",
                    "categories",
                    "status",
                    "json_version",
                    "data_api_version",
                    "validation_errors",
                    "endpoint_mode",
                    "handler",
                    "health_status",
                    "preview",
                    "last_synced_at",
                    "created_at",
                    "updated_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/flows/{id}/exchanges": {
      "get": {
        "operationId": "listFlowExchanges",
        "summary": "Listar trocas do endpoint",
        "description": "Chamadas da Meta ao endpoint de data exchange nos últimos 7 dias, mais recentes primeiro: ação, tela, resultado e tempos. Nunca traz `data` nem o `flow_token`. Permissão: `read`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID do Flow (`flw_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de trocas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID da troca (`fex_…`)."
                          },
                          "action": {
                            "enum": [
                              "ping",
                              "INIT",
                              "BACK",
                              "data_exchange",
                              "error_notification"
                            ],
                            "type": "string",
                            "description": "`ping`, `INIT`, `BACK`, `data_exchange` ou `error_notification`."
                          },
                          "screen": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Tela do Flow, quando há."
                          },
                          "result": {
                            "enum": [
                              "ok",
                              "handler_error",
                              "handler_timeout",
                              "handler_invalid",
                              "decrypt_failed",
                              "signature_invalid",
                              "rate_limited",
                              "flow_not_found"
                            ],
                            "type": "string",
                            "description": "Resultado: `ok`, `handler_error`, `handler_timeout`, `handler_invalid`, `decrypt_failed`, `signature_invalid`, `rate_limited` ou `flow_not_found`."
                          },
                          "handler_status": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Status HTTP do handler."
                          },
                          "duration_ms": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Tempo total da troca (ms)."
                          },
                          "handler_duration_ms": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Tempo do handler (ms)."
                          },
                          "request_bytes": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Tamanho do pedido da Meta."
                          },
                          "response_bytes": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Tamanho da resposta."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo da falha, sem dado pessoal."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando foi criado."
                          }
                        },
                        "required": [
                          "id",
                          "action",
                          "screen",
                          "result",
                          "handler_status",
                          "duration_ms",
                          "handler_duration_ms",
                          "request_bytes",
                          "response_bytes",
                          "error",
                          "created_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/flow-key/rotate": {
      "post": {
        "operationId": "rotateFlowKey",
        "summary": "Trocar chave dos Flows",
        "description": "Gera um par RSA 2048 novo para a conta (WABA) da conexão e envia a todos os números ativos; a chave anterior ainda decifra por 24 h. Permissão: `admin`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID da conexão do WhatsApp. Opcional com chave de conexão (usa a conexão da chave)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Impressão digital e envios por número.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "fingerprint": {
                      "type": "string",
                      "description": "SHA-256 da chave pública nova."
                    },
                    "uploads": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {
                        "type": "object",
                        "properties": {
                          "uploaded_at": {
                            "type": "string",
                            "description": "Quando a chave foi enviada ao número."
                          },
                          "signature_status": {
                            "enum": [
                              "VALID",
                              "MISMATCH",
                              "unknown"
                            ],
                            "type": "string",
                            "description": "`VALID`, `MISMATCH` ou `unknown`."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Erro da Meta no envio, quando houve."
                          }
                        },
                        "required": [
                          "uploaded_at",
                          "signature_status",
                          "error"
                        ]
                      },
                      "description": "Envio da chave por `phone_number_id`."
                    }
                  },
                  "required": [
                    "fingerprint",
                    "uploads"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/catalogs": {
      "get": {
        "operationId": "listCatalogs",
        "summary": "Listar catálogos",
        "description": "Catálogos conhecidos da organização; com `connection_id`, só os da conta de mensagens (WABA) da conexão. Chave presa a conexões precisa de `connection_id`. Permissão: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão do WhatsApp (`con_…`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Catálogos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do catálogo no Messajo (`cat_…`).",
                            "examples": [
                              "cat_0193a1b2c3d47e8f"
                            ]
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID do catálogo ou do produto na Meta."
                          },
                          "messaging_account_id": {
                            "type": "string",
                            "description": "Conta de mensagens (WABA) do catálogo."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nome."
                          },
                          "vertical": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Vertical do catálogo na Meta (por exemplo `commerce`)."
                          },
                          "product_count": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quantidade de produtos informada pela Meta."
                          },
                          "linked": {
                            "type": "boolean",
                            "description": "Se o catálogo está ligado à WABA agora."
                          },
                          "linked_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando foi ligado (ISO 8601)."
                          },
                          "commerce_settings": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {},
                            "description": "Últimas configurações de comércio lidas, por `phone_number_id`."
                          },
                          "last_synced_at": {
                            "type": "string",
                            "description": "Última leitura na Meta (ISO 8601)."
                          }
                        },
                        "required": [
                          "id",
                          "external_id",
                          "messaging_account_id",
                          "name",
                          "vertical",
                          "product_count",
                          "linked",
                          "linked_at",
                          "commerce_settings",
                          "last_synced_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createCatalog",
        "summary": "Criar catálogo",
        "description": "Cria o catálogo no portfólio empresarial da conexão e o liga à WABA. Exige o token com `catalog_management` (`403 commerce_permission_missing` sem ele). Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão do WhatsApp (`con_…`)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nome."
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O catálogo criado e ligado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do catálogo no Messajo (`cat_…`).",
                      "examples": [
                        "cat_0193a1b2c3d47e8f"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do catálogo ou do produto na Meta."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Conta de mensagens (WABA) do catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Vertical do catálogo na Meta (por exemplo `commerce`)."
                    },
                    "product_count": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quantidade de produtos informada pela Meta."
                    },
                    "linked": {
                      "type": "boolean",
                      "description": "Se o catálogo está ligado à WABA agora."
                    },
                    "linked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi ligado (ISO 8601)."
                    },
                    "commerce_settings": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Últimas configurações de comércio lidas, por `phone_number_id`."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta (ISO 8601)."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "messaging_account_id",
                    "name",
                    "vertical",
                    "product_count",
                    "linked",
                    "linked_at",
                    "commerce_settings",
                    "last_synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/catalogs/link": {
      "post": {
        "operationId": "linkCatalog",
        "summary": "Ligar catálogo",
        "description": "Liga à WABA da conexão um catálogo que já existe na Meta (`catalog_external_id`). A WABA tem no máximo um catálogo ligado. Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão do WhatsApp (`con_…`)."
                  },
                  "catalog_external_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID do catálogo ou do produto na Meta."
                  }
                },
                "required": [
                  "catalog_external_id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O catálogo ligado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do catálogo no Messajo (`cat_…`).",
                      "examples": [
                        "cat_0193a1b2c3d47e8f"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do catálogo ou do produto na Meta."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Conta de mensagens (WABA) do catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Vertical do catálogo na Meta (por exemplo `commerce`)."
                    },
                    "product_count": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quantidade de produtos informada pela Meta."
                    },
                    "linked": {
                      "type": "boolean",
                      "description": "Se o catálogo está ligado à WABA agora."
                    },
                    "linked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi ligado (ISO 8601)."
                    },
                    "commerce_settings": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Últimas configurações de comércio lidas, por `phone_number_id`."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta (ISO 8601)."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "messaging_account_id",
                    "name",
                    "vertical",
                    "product_count",
                    "linked",
                    "linked_at",
                    "commerce_settings",
                    "last_synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/catalogs/{id}/unlink": {
      "post": {
        "operationId": "unlinkCatalog",
        "summary": "Desligar catálogo",
        "description": "Desliga o catálogo da WABA da conexão; o catálogo continua no portfólio. Catálogo de outra WABA → `409 catalog_not_linked`. Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do catálogo no Messajo (`cat_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão do WhatsApp (`con_…`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O catálogo desligado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do catálogo no Messajo (`cat_…`).",
                      "examples": [
                        "cat_0193a1b2c3d47e8f"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do catálogo ou do produto na Meta."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Conta de mensagens (WABA) do catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Vertical do catálogo na Meta (por exemplo `commerce`)."
                    },
                    "product_count": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quantidade de produtos informada pela Meta."
                    },
                    "linked": {
                      "type": "boolean",
                      "description": "Se o catálogo está ligado à WABA agora."
                    },
                    "linked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi ligado (ISO 8601)."
                    },
                    "commerce_settings": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Últimas configurações de comércio lidas, por `phone_number_id`."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta (ISO 8601)."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "messaging_account_id",
                    "name",
                    "vertical",
                    "product_count",
                    "linked",
                    "linked_at",
                    "commerce_settings",
                    "last_synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/catalogs/{id}/sync": {
      "post": {
        "operationId": "syncCatalog",
        "summary": "Sincronizar catálogo",
        "description": "Relê da Meta os produtos do catálogo e atualiza o cache usado na checagem de `retailer_id` no envio. Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do catálogo no Messajo (`cat_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "O catálogo sincronizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do catálogo no Messajo (`cat_…`).",
                      "examples": [
                        "cat_0193a1b2c3d47e8f"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do catálogo ou do produto na Meta."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Conta de mensagens (WABA) do catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Vertical do catálogo na Meta (por exemplo `commerce`)."
                    },
                    "product_count": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quantidade de produtos informada pela Meta."
                    },
                    "linked": {
                      "type": "boolean",
                      "description": "Se o catálogo está ligado à WABA agora."
                    },
                    "linked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando foi ligado (ISO 8601)."
                    },
                    "commerce_settings": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Últimas configurações de comércio lidas, por `phone_number_id`."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta (ISO 8601)."
                    }
                  },
                  "required": [
                    "id",
                    "external_id",
                    "messaging_account_id",
                    "name",
                    "vertical",
                    "product_count",
                    "linked",
                    "linked_at",
                    "commerce_settings",
                    "last_synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/connections/{id}/commerce-settings": {
      "get": {
        "operationId": "getCommerceSettings",
        "summary": "Consultar configurações de comércio",
        "description": "Carrinho ligado e catálogo visível no perfil do número, lidos da Meta. Permissão: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão do WhatsApp (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "As configurações do número.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "is_cart_enabled": {
                      "type": "boolean",
                      "description": "Carrinho ligado no número."
                    },
                    "is_catalog_visible": {
                      "type": "boolean",
                      "description": "Catálogo visível no perfil do número."
                    }
                  },
                  "required": [
                    "is_cart_enabled",
                    "is_catalog_visible"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "put": {
        "operationId": "updateCommerceSettings",
        "summary": "Alterar configurações de comércio",
        "description": "Liga ou desliga o carrinho e a visibilidade do catálogo no número. Mande pelo menos um campo. Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão do WhatsApp (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "is_cart_enabled": {
                    "type": "boolean",
                    "description": "Carrinho ligado no número."
                  },
                  "is_catalog_visible": {
                    "type": "boolean",
                    "description": "Catálogo visível no perfil do número."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "As configurações depois da mudança.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "is_cart_enabled": {
                      "type": "boolean",
                      "description": "Carrinho ligado no número."
                    },
                    "is_catalog_visible": {
                      "type": "boolean",
                      "description": "Catálogo visível no perfil do número."
                    }
                  },
                  "required": [
                    "is_cart_enabled",
                    "is_catalog_visible"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/catalogs/{id}/products": {
      "get": {
        "operationId": "listProducts",
        "summary": "Listar produtos",
        "description": "Produtos do catálogo no cache do Messajo (sincronizado todo dia e em `POST /catalogs/{id}/sync`). Permissão: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do catálogo no Messajo (`cat_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Produtos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do produto no Messajo (`prd_…`).",
                            "examples": [
                              "prd_0193a1b2c3d47e8f"
                            ]
                          },
                          "catalog_id": {
                            "type": "string",
                            "description": "ID do catálogo no Messajo (`cat_…`)."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID do catálogo ou do produto na Meta."
                          },
                          "retailer_id": {
                            "type": "string",
                            "description": "SKU do produto (`retailer_id`), único no catálogo."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nome."
                          },
                          "description": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Descrição."
                          },
                          "amount_minor": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Preço em unidade menor (centavos), inteiro."
                          },
                          "sale_amount_minor": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Preço promocional em unidade menor (centavos)."
                          },
                          "currency": {
                            "type": "string",
                            "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                          },
                          "availability": {
                            "type": "string",
                            "description": "Disponibilidade (`in stock`, `out of stock`, …)."
                          },
                          "condition": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Condição: `new`, `refurbished` ou `used`."
                          },
                          "visibility": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Visibilidade na Meta: `published` ou `staging`."
                          },
                          "image_url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "URL `https` pública da imagem."
                          },
                          "url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "URL `https` da página do produto."
                          },
                          "brand": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Marca."
                          },
                          "review_status": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Status da revisão da Meta."
                          },
                          "last_synced_at": {
                            "type": "string",
                            "description": "Última leitura na Meta (ISO 8601)."
                          }
                        },
                        "required": [
                          "id",
                          "catalog_id",
                          "external_id",
                          "retailer_id",
                          "name",
                          "description",
                          "amount_minor",
                          "sale_amount_minor",
                          "currency",
                          "availability",
                          "condition",
                          "visibility",
                          "image_url",
                          "url",
                          "brand",
                          "review_status",
                          "last_synced_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createProduct",
        "summary": "Criar produto",
        "description": "Cria o produto no catálogo da Meta. Preço em unidade menor (`amount_minor`, inteiro: R$ 59,90 = `5990`). Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do catálogo no Messajo (`cat_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "retailer_id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "SKU do produto (`retailer_id`), único no catálogo."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nome."
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 9999,
                    "description": "Descrição."
                  },
                  "amount_minor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Preço em unidade menor (centavos), inteiro."
                  },
                  "sale_amount_minor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Preço promocional em unidade menor (centavos)."
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                  },
                  "availability": {
                    "enum": [
                      "in stock",
                      "out of stock",
                      "preorder",
                      "available for order",
                      "discontinued"
                    ],
                    "type": "string",
                    "description": "Disponibilidade (`in stock`, `out of stock`, …)."
                  },
                  "condition": {
                    "enum": [
                      "new",
                      "refurbished",
                      "used"
                    ],
                    "type": "string",
                    "description": "Condição: `new`, `refurbished` ou `used`."
                  },
                  "visibility": {
                    "enum": [
                      "published",
                      "staging"
                    ],
                    "type": "string",
                    "description": "Visibilidade na Meta: `published` ou `staging`."
                  },
                  "image_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL `https` pública da imagem."
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL `https` da página do produto."
                  },
                  "brand": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Marca."
                  }
                },
                "required": [
                  "retailer_id",
                  "name",
                  "amount_minor",
                  "currency",
                  "image_url"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "O produto criado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do produto no Messajo (`prd_…`).",
                      "examples": [
                        "prd_0193a1b2c3d47e8f"
                      ]
                    },
                    "catalog_id": {
                      "type": "string",
                      "description": "ID do catálogo no Messajo (`cat_…`)."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do catálogo ou do produto na Meta."
                    },
                    "retailer_id": {
                      "type": "string",
                      "description": "SKU do produto (`retailer_id`), único no catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição."
                    },
                    "amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Preço em unidade menor (centavos), inteiro."
                    },
                    "sale_amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Preço promocional em unidade menor (centavos)."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                    },
                    "availability": {
                      "type": "string",
                      "description": "Disponibilidade (`in stock`, `out of stock`, …)."
                    },
                    "condition": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Condição: `new`, `refurbished` ou `used`."
                    },
                    "visibility": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Visibilidade na Meta: `published` ou `staging`."
                    },
                    "image_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` pública da imagem."
                    },
                    "url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` da página do produto."
                    },
                    "brand": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Marca."
                    },
                    "review_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status da revisão da Meta."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta (ISO 8601)."
                    }
                  },
                  "required": [
                    "id",
                    "catalog_id",
                    "external_id",
                    "retailer_id",
                    "name",
                    "description",
                    "amount_minor",
                    "sale_amount_minor",
                    "currency",
                    "availability",
                    "condition",
                    "visibility",
                    "image_url",
                    "url",
                    "brand",
                    "review_status",
                    "last_synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/products/{id}": {
      "get": {
        "operationId": "getProduct",
        "summary": "Consultar produto",
        "description": "Um produto do cache, com o status de revisão da Meta. Permissão: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do produto no Messajo (`prd_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O produto.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do produto no Messajo (`prd_…`).",
                      "examples": [
                        "prd_0193a1b2c3d47e8f"
                      ]
                    },
                    "catalog_id": {
                      "type": "string",
                      "description": "ID do catálogo no Messajo (`cat_…`)."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do catálogo ou do produto na Meta."
                    },
                    "retailer_id": {
                      "type": "string",
                      "description": "SKU do produto (`retailer_id`), único no catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição."
                    },
                    "amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Preço em unidade menor (centavos), inteiro."
                    },
                    "sale_amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Preço promocional em unidade menor (centavos)."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                    },
                    "availability": {
                      "type": "string",
                      "description": "Disponibilidade (`in stock`, `out of stock`, …)."
                    },
                    "condition": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Condição: `new`, `refurbished` ou `used`."
                    },
                    "visibility": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Visibilidade na Meta: `published` ou `staging`."
                    },
                    "image_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` pública da imagem."
                    },
                    "url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` da página do produto."
                    },
                    "brand": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Marca."
                    },
                    "review_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status da revisão da Meta."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta (ISO 8601)."
                    }
                  },
                  "required": [
                    "id",
                    "catalog_id",
                    "external_id",
                    "retailer_id",
                    "name",
                    "description",
                    "amount_minor",
                    "sale_amount_minor",
                    "currency",
                    "availability",
                    "condition",
                    "visibility",
                    "image_url",
                    "url",
                    "brand",
                    "review_status",
                    "last_synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "patch": {
        "operationId": "updateProduct",
        "summary": "Alterar produto",
        "description": "Troca campos do produto na Meta; só os campos enviados mudam. Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do produto no Messajo (`prd_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nome."
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 9999,
                    "description": "Descrição."
                  },
                  "amount_minor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Preço em unidade menor (centavos), inteiro."
                  },
                  "sale_amount_minor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Preço promocional em unidade menor (centavos)."
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                  },
                  "availability": {
                    "enum": [
                      "in stock",
                      "out of stock",
                      "preorder",
                      "available for order",
                      "discontinued"
                    ],
                    "type": "string",
                    "description": "Disponibilidade (`in stock`, `out of stock`, …)."
                  },
                  "condition": {
                    "enum": [
                      "new",
                      "refurbished",
                      "used"
                    ],
                    "type": "string",
                    "description": "Condição: `new`, `refurbished` ou `used`."
                  },
                  "visibility": {
                    "enum": [
                      "published",
                      "staging"
                    ],
                    "type": "string",
                    "description": "Visibilidade na Meta: `published` ou `staging`."
                  },
                  "image_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL `https` pública da imagem."
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL `https` da página do produto."
                  },
                  "brand": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Marca."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O produto alterado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do produto no Messajo (`prd_…`).",
                      "examples": [
                        "prd_0193a1b2c3d47e8f"
                      ]
                    },
                    "catalog_id": {
                      "type": "string",
                      "description": "ID do catálogo no Messajo (`cat_…`)."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID do catálogo ou do produto na Meta."
                    },
                    "retailer_id": {
                      "type": "string",
                      "description": "SKU do produto (`retailer_id`), único no catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nome."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descrição."
                    },
                    "amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Preço em unidade menor (centavos), inteiro."
                    },
                    "sale_amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Preço promocional em unidade menor (centavos)."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                    },
                    "availability": {
                      "type": "string",
                      "description": "Disponibilidade (`in stock`, `out of stock`, …)."
                    },
                    "condition": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Condição: `new`, `refurbished` ou `used`."
                    },
                    "visibility": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Visibilidade na Meta: `published` ou `staging`."
                    },
                    "image_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` pública da imagem."
                    },
                    "url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` da página do produto."
                    },
                    "brand": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Marca."
                    },
                    "review_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Status da revisão da Meta."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última leitura na Meta (ISO 8601)."
                    }
                  },
                  "required": [
                    "id",
                    "catalog_id",
                    "external_id",
                    "retailer_id",
                    "name",
                    "description",
                    "amount_minor",
                    "sale_amount_minor",
                    "currency",
                    "availability",
                    "condition",
                    "visibility",
                    "image_url",
                    "url",
                    "brand",
                    "review_status",
                    "last_synced_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteProduct",
        "summary": "Apagar produto",
        "description": "Apaga o produto na Meta e o tira do cache. Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do produto no Messajo (`prd_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmação.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do produto no Messajo (`prd_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Sempre `true`."
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/orders": {
      "get": {
        "operationId": "listOrders",
        "summary": "Listar pedidos",
        "description": "Pedidos da organização, mais recentes primeiro: carrinhos recebidos (`cart`) e cobranças enviadas com `order_details`. Chave presa a conexões vê só os das suas conexões. Permissão: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor da página seguinte: o `next_cursor` da resposta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Itens por página, de 1 a 100 (padrão 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID da conexão do WhatsApp (`con_…`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "cart_received",
                "pending",
                "processing",
                "partially_shipped",
                "shipped",
                "completed",
                "canceled"
              ],
              "type": "string",
              "description": "Status do pedido."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de pedidos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do pedido (`ord_…`).",
                            "examples": [
                              "ord_0193a1b2c3d47e8f"
                            ]
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID da conexão do WhatsApp (`con_…`)."
                          },
                          "origin": {
                            "enum": [
                              "cart",
                              "order_details"
                            ],
                            "type": "string",
                            "description": "Origem: `cart` (carrinho do cliente) ou `order_details` (cobrança enviada)."
                          },
                          "reference_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "`reference_id` do `order_details`, único na conexão."
                          },
                          "catalog_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID do catálogo no Messajo (`cat_…`)."
                          },
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "retailer_id": {
                                  "type": "string",
                                  "description": "SKU do produto (`retailer_id`), único no catálogo."
                                },
                                "name": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "Nome."
                                },
                                "quantity": {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991,
                                  "description": "Quantidade."
                                },
                                "amount_minor": {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991,
                                  "description": "Preço em unidade menor (centavos), inteiro."
                                },
                                "sale_amount_minor": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Preço promocional em unidade menor (centavos)."
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "currency": {
                                  "type": "string",
                                  "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                                }
                              },
                              "required": [
                                "retailer_id",
                                "name",
                                "quantity",
                                "amount_minor",
                                "sale_amount_minor",
                                "currency"
                              ]
                            },
                            "description": "Itens do pedido."
                          },
                          "currency": {
                            "type": "string",
                            "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                          },
                          "subtotal_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Subtotal em unidade menor."
                          },
                          "tax_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Impostos em unidade menor."
                          },
                          "shipping_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Frete em unidade menor."
                          },
                          "discount_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Desconto em unidade menor."
                          },
                          "total_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Total em unidade menor."
                          },
                          "status": {
                            "enum": [
                              "cart_received",
                              "pending",
                              "processing",
                              "partially_shipped",
                              "shipped",
                              "completed",
                              "canceled"
                            ],
                            "type": "string",
                            "description": "Status do pedido."
                          },
                          "status_description": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Texto do último `order_status`."
                          },
                          "payment_status": {
                            "enum": [
                              "none",
                              "pending",
                              "captured",
                              "failed",
                              "expired",
                              "unknown"
                            ],
                            "type": "string",
                            "description": "Status do pagamento."
                          },
                          "payment_method": {
                            "anyOf": [
                              {
                                "enum": [
                                  "pix_dynamic_code",
                                  "payment_link",
                                  "boleto",
                                  "offsite_card"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Meio de pagamento informado."
                          },
                          "expires_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Quando a cobrança vence (ISO 8601)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Criação (ISO 8601)."
                          }
                        },
                        "required": [
                          "id",
                          "connection_id",
                          "origin",
                          "reference_id",
                          "catalog_id",
                          "items",
                          "currency",
                          "subtotal_minor",
                          "tax_minor",
                          "shipping_minor",
                          "discount_minor",
                          "total_minor",
                          "status",
                          "status_description",
                          "payment_status",
                          "payment_method",
                          "expires_at",
                          "created_at"
                        ]
                      },
                      "description": "Itens da página, do mais novo para o mais antigo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor para a próxima página; `null` quando não há mais itens."
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/orders/{id}": {
      "get": {
        "operationId": "getOrder",
        "summary": "Consultar pedido",
        "description": "Um pedido com itens, totais em unidade menor, status e status do pagamento. Permissão: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do pedido (`ord_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "O pedido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do pedido (`ord_…`).",
                      "examples": [
                        "ord_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp (`con_…`)."
                    },
                    "origin": {
                      "enum": [
                        "cart",
                        "order_details"
                      ],
                      "type": "string",
                      "description": "Origem: `cart` (carrinho do cliente) ou `order_details` (cobrança enviada)."
                    },
                    "reference_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`reference_id` do `order_details`, único na conexão."
                    },
                    "catalog_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do catálogo no Messajo (`cat_…`)."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "retailer_id": {
                            "type": "string",
                            "description": "SKU do produto (`retailer_id`), único no catálogo."
                          },
                          "name": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome."
                          },
                          "quantity": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Quantidade."
                          },
                          "amount_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Preço em unidade menor (centavos), inteiro."
                          },
                          "sale_amount_minor": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Preço promocional em unidade menor (centavos)."
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "currency": {
                            "type": "string",
                            "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                          }
                        },
                        "required": [
                          "retailer_id",
                          "name",
                          "quantity",
                          "amount_minor",
                          "sale_amount_minor",
                          "currency"
                        ]
                      },
                      "description": "Itens do pedido."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                    },
                    "subtotal_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Subtotal em unidade menor."
                    },
                    "tax_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Impostos em unidade menor."
                    },
                    "shipping_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Frete em unidade menor."
                    },
                    "discount_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Desconto em unidade menor."
                    },
                    "total_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Total em unidade menor."
                    },
                    "status": {
                      "enum": [
                        "cart_received",
                        "pending",
                        "processing",
                        "partially_shipped",
                        "shipped",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status do pedido."
                    },
                    "status_description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto do último `order_status`."
                    },
                    "payment_status": {
                      "enum": [
                        "none",
                        "pending",
                        "captured",
                        "failed",
                        "expired",
                        "unknown"
                      ],
                      "type": "string",
                      "description": "Status do pagamento."
                    },
                    "payment_method": {
                      "anyOf": [
                        {
                          "enum": [
                            "pix_dynamic_code",
                            "payment_link",
                            "boleto",
                            "offsite_card"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Meio de pagamento informado."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a cobrança vence (ISO 8601)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Criação (ISO 8601)."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "origin",
                    "reference_id",
                    "catalog_id",
                    "items",
                    "currency",
                    "subtotal_minor",
                    "tax_minor",
                    "shipping_minor",
                    "discount_minor",
                    "total_minor",
                    "status",
                    "status_description",
                    "payment_status",
                    "payment_method",
                    "expires_at",
                    "created_at"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/orders/{id}/payment": {
      "post": {
        "operationId": "markOrderPayment",
        "summary": "Informar pagamento",
        "description": "Pix fora do WhatsApp não tem webhook de pagamento: concilie com o seu PSP e informe aqui `captured` ou `failed`. Com `notify: true` e `captured`, o Messajo manda ao cliente o `order_status processing` (texto em `message`). Só pedido `pending` ainda não pago; senão `409 order_invalid_transition`. Permissão: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID do pedido (`ord_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "enum": [
                      "captured",
                      "failed"
                    ],
                    "type": "string",
                    "description": "Resultado da conciliação: `captured` ou `failed`."
                  },
                  "notify": {
                    "type": "boolean",
                    "description": "Com `captured`, manda ao cliente o `order_status processing`."
                  },
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1024,
                    "description": "Texto do aviso ao cliente (até 1024 caracteres)."
                  }
                },
                "required": [
                  "status"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "O pedido atualizado e o ID da mensagem de aviso, se houve.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID do pedido (`ord_…`).",
                      "examples": [
                        "ord_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID da conexão do WhatsApp (`con_…`)."
                    },
                    "origin": {
                      "enum": [
                        "cart",
                        "order_details"
                      ],
                      "type": "string",
                      "description": "Origem: `cart` (carrinho do cliente) ou `order_details` (cobrança enviada)."
                    },
                    "reference_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`reference_id` do `order_details`, único na conexão."
                    },
                    "catalog_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID do catálogo no Messajo (`cat_…`)."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "retailer_id": {
                            "type": "string",
                            "description": "SKU do produto (`retailer_id`), único no catálogo."
                          },
                          "name": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nome."
                          },
                          "quantity": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Quantidade."
                          },
                          "amount_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Preço em unidade menor (centavos), inteiro."
                          },
                          "sale_amount_minor": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Preço promocional em unidade menor (centavos)."
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "currency": {
                            "type": "string",
                            "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                          }
                        },
                        "required": [
                          "retailer_id",
                          "name",
                          "quantity",
                          "amount_minor",
                          "sale_amount_minor",
                          "currency"
                        ]
                      },
                      "description": "Itens do pedido."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moeda ISO 4217 (por exemplo `BRL`)."
                    },
                    "subtotal_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Subtotal em unidade menor."
                    },
                    "tax_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Impostos em unidade menor."
                    },
                    "shipping_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Frete em unidade menor."
                    },
                    "discount_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Desconto em unidade menor."
                    },
                    "total_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Total em unidade menor."
                    },
                    "status": {
                      "enum": [
                        "cart_received",
                        "pending",
                        "processing",
                        "partially_shipped",
                        "shipped",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Status do pedido."
                    },
                    "status_description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto do último `order_status`."
                    },
                    "payment_status": {
                      "enum": [
                        "none",
                        "pending",
                        "captured",
                        "failed",
                        "expired",
                        "unknown"
                      ],
                      "type": "string",
                      "description": "Status do pagamento."
                    },
                    "payment_method": {
                      "anyOf": [
                        {
                          "enum": [
                            "pix_dynamic_code",
                            "payment_link",
                            "boleto",
                            "offsite_card"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Meio de pagamento informado."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Quando a cobrança vence (ISO 8601)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Criação (ISO 8601)."
                    },
                    "notification_message_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID da mensagem de aviso enviada, ou `null`."
                    }
                  },
                  "required": [
                    "id",
                    "connection_id",
                    "origin",
                    "reference_id",
                    "catalog_id",
                    "items",
                    "currency",
                    "subtotal_minor",
                    "tax_minor",
                    "shipping_minor",
                    "discount_minor",
                    "total_minor",
                    "status",
                    "status_description",
                    "payment_status",
                    "payment_method",
                    "expires_at",
                    "created_at",
                    "notification_message_id"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/templates/authentication": {
      "post": {
        "operationId": "createAuthTemplate",
        "summary": "Criar template de autenticação",
        "description": "Cria (ou atualiza) um template `AUTHENTICATION` em cada idioma, com botão copy code, one-tap ou zero-tap. O texto é o fixo da Meta. Mande o código depois com `POST /messages` `type: \"otp\"`: o código vai só para a Meta e é gravado mascarado. Permissão: `templates`.",
        "tags": [
          "templates"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão do WhatsApp (`con_…`)."
                  },
                  "languages": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 20,
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z]{2,3}(_[A-Z]{2})?$"
                    },
                    "description": "Idiomas (1 a 20), por exemplo `pt_BR`."
                  },
                  "add_security_recommendation": {
                    "type": "boolean",
                    "description": "Acrescenta o aviso de segurança da Meta ao corpo."
                  },
                  "code_expiration_minutes": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 90,
                    "description": "Validade do código em minutos (1 a 90), mostrada no rodapé."
                  },
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z0-9_]{1,512}$",
                    "description": "Nome do template (minúsculas, números e `_`)."
                  },
                  "message_send_ttl_seconds": {
                    "type": "integer",
                    "minimum": 30,
                    "maximum": 900,
                    "description": "Prazo de entrega em segundos (30 a 900)."
                  },
                  "button": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "otp_type": {
                            "const": "COPY_CODE"
                          },
                          "text": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 25
                          }
                        },
                        "required": [
                          "otp_type"
                        ]
                      },
                      {
                        "type": "object",
                        "properties": {
                          "otp_type": {
                            "const": "ONE_TAP"
                          },
                          "text": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 25
                          },
                          "autofill_text": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 25
                          },
                          "supported_apps": {
                            "type": "array",
                            "minItems": 1,
                            "maxItems": 5,
                            "items": {
                              "type": "object",
                              "properties": {
                                "package_name": {
                                  "type": "string",
                                  "maxLength": 224,
                                  "pattern": "^[A-Za-z]\\w*(\\.[A-Za-z]\\w*)+$"
                                },
                                "signature_hash": {
                                  "type": "string",
                                  "minLength": 11,
                                  "maxLength": 11
                                }
                              },
                              "required": [
                                "package_name",
                                "signature_hash"
                              ]
                            }
                          }
                        },
                        "required": [
                          "otp_type",
                          "supported_apps"
                        ]
                      },
                      {
                        "type": "object",
                        "properties": {
                          "otp_type": {
                            "const": "ZERO_TAP"
                          },
                          "text": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 25
                          },
                          "autofill_text": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 25
                          },
                          "supported_apps": {
                            "type": "array",
                            "minItems": 1,
                            "maxItems": 5,
                            "items": {
                              "type": "object",
                              "properties": {
                                "package_name": {
                                  "type": "string",
                                  "maxLength": 224,
                                  "pattern": "^[A-Za-z]\\w*(\\.[A-Za-z]\\w*)+$"
                                },
                                "signature_hash": {
                                  "type": "string",
                                  "minLength": 11,
                                  "maxLength": 11
                                }
                              },
                              "required": [
                                "package_name",
                                "signature_hash"
                              ]
                            }
                          },
                          "zero_tap_terms_accepted": {
                            "const": true
                          }
                        },
                        "required": [
                          "otp_type",
                          "supported_apps",
                          "zero_tap_terms_accepted"
                        ]
                      }
                    ],
                    "description": "Botão OTP: `COPY_CODE`, `ONE_TAP` ou `ZERO_TAP` (estes com `supported_apps`)."
                  }
                },
                "required": [
                  "languages",
                  "add_security_recommendation",
                  "name",
                  "button"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Um template por idioma.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID do template no Messajo (`tpl_…`).",
                            "examples": [
                              "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "messaging_account_id": {
                            "type": "string",
                            "description": "Conta do WhatsApp Business (WABA) do template."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID do template na Meta."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nome (minúsculas, números e `_`)."
                          },
                          "language": {
                            "type": "string",
                            "description": "Idioma, ex.: `pt_BR`."
                          },
                          "category": {
                            "enum": [
                              "MARKETING",
                              "UTILITY",
                              "AUTHENTICATION"
                            ],
                            "type": "string",
                            "description": "Categoria: `MARKETING`, `UTILITY` ou `AUTHENTICATION`."
                          },
                          "previous_category": {
                            "anyOf": [
                              {
                                "enum": [
                                  "MARKETING",
                                  "UTILITY",
                                  "AUTHENTICATION"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Categoria anterior, quando a Meta reclassificou."
                          },
                          "status": {
                            "enum": [
                              "APPROVED",
                              "PENDING",
                              "REJECTED",
                              "PAUSED",
                              "DISABLED",
                              "IN_APPEAL",
                              "PENDING_DELETION",
                              "DELETED",
                              "ARCHIVED",
                              "LIMIT_EXCEEDED",
                              "LOCKED",
                              "FLAGGED",
                              "REINSTATED"
                            ],
                            "type": "string",
                            "description": "Status na Meta, ex.: `APPROVED`, `PENDING`, `REJECTED`."
                          },
                          "rejected_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo da rejeição, quando há."
                          },
                          "quality_score": {
                            "enum": [
                              "GREEN",
                              "YELLOW",
                              "RED",
                              "UNKNOWN"
                            ],
                            "type": "string",
                            "description": "Qualidade: `GREEN`, `YELLOW`, `RED` ou `UNKNOWN`."
                          },
                          "parameter_format": {
                            "enum": [
                              "POSITIONAL",
                              "NAMED"
                            ],
                            "type": "string",
                            "description": "Formato das variáveis: `POSITIONAL` ou `NAMED`."
                          },
                          "components": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            "description": "Componentes no formato da Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                          },
                          "last_synced_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última leitura na Meta (ISO 8601, UTC)."
                          },
                          "status_updated_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última mudança de status (ISO 8601, UTC)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Quando foi criado no Messajo (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Última alteração (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "messaging_account_id",
                          "external_id",
                          "name",
                          "language",
                          "category",
                          "previous_category",
                          "status",
                          "rejected_reason",
                          "quality_score",
                          "parameter_format",
                          "components",
                          "last_synced_at",
                          "status_updated_at",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Templates criados, um por idioma."
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/templates/authentication/preview": {
      "post": {
        "operationId": "previewAuthTemplate",
        "summary": "Pré-visualizar template de autenticação",
        "description": "Os textos que a Meta vai usar em cada idioma com as opções escolhidas. Permissão: `templates`.",
        "tags": [
          "templates"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID da conexão do WhatsApp (`con_…`)."
                  },
                  "languages": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 20,
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z]{2,3}(_[A-Z]{2})?$"
                    },
                    "description": "Idiomas (1 a 20), por exemplo `pt_BR`."
                  },
                  "add_security_recommendation": {
                    "type": "boolean",
                    "description": "Acrescenta o aviso de segurança da Meta ao corpo."
                  },
                  "code_expiration_minutes": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 90,
                    "description": "Validade do código em minutos (1 a 90), mostrada no rodapé."
                  }
                },
                "required": [
                  "languages",
                  "add_security_recommendation"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Prévias por idioma.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "previews": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "language": {
                            "type": "string",
                            "description": "Idioma."
                          },
                          "body": {
                            "type": "string",
                            "description": "Corpo."
                          },
                          "footer": {
                            "type": "string",
                            "description": "Rodapé."
                          },
                          "buttons": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "text": {
                                  "type": "string"
                                },
                                "autofill_text": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "text"
                              ]
                            },
                            "description": "Botões."
                          }
                        },
                        "required": [
                          "language",
                          "body",
                          "buttons"
                        ]
                      },
                      "description": "Prévias por idioma."
                    }
                  },
                  "required": [
                    "previews"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ]
      }
    },
    "/usage/costs": {
      "get": {
        "operationId": "getUsageCosts",
        "summary": "Custos do WhatsApp",
        "description": "Custo cobrado pela Meta no período, na moeda da conta do WhatsApp. `estimate` é calculado pelo Messajo na entrega de cada mensagem; `official` é o valor aproximado informado pela Meta (chega com até 3 dias de atraso).",
        "tags": [
          "usage"
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "description": "Primeiro dia (UTC, `AAAA-MM-DD`). Padrão: dia 1 do mês atual"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "description": "Último dia, inclusivo. Padrão: hoje. Máximo de 366 dias"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Só esta conexão"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[A-Z]{3}$",
              "description": "Moeda (ISO 4217). Obrigatória quando a organização tem contas em mais de uma moeda"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "group_by",
            "in": "query",
            "schema": {
              "enum": [
                "day",
                "campaign",
                "template",
                "category",
                "connection"
              ],
              "type": "string",
              "default": "day",
              "description": "Recorte: dia, campanha, template, conexão ou categoria"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Itens do recorte pedido",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "currency": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Moeda dos valores; `null` se a organização ainda não tem custo"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string",
                            "description": "Dia (`AAAA-MM-DD`), id da campanha, `nome:idioma` do template, id da conexão ou categoria"
                          },
                          "estimate": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Estimativa do Messajo (string decimal); `null` sem cotação/tabela"
                          },
                          "official": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Valor aproximado da Meta (string decimal); `null` enquanto a Meta não informa. Ausente nos recortes por campanha e template"
                          }
                        },
                        "required": [
                          "key",
                          "estimate"
                        ]
                      }
                    }
                  },
                  "required": [
                    "currency",
                    "items"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/whatsapp/{id}/{path}": {
      "get": {
        "operationId": "mirrorGet",
        "summary": "Espelho da Meta (leitura)",
        "description": "Repassa um `GET` para a Graph API da Meta com o token da conexão, sem mudar corpo nem resposta (erros da Meta voltam como a Meta mandou). `{id}` é o `phone_number_id` ou o `messaging_account_id` (WABA) de uma conexão da organização; nós avulsos ficam em `{phone_number_id}/nodes/{node_id}`. Referência dos caminhos: https://developers.facebook.com/docs/whatsapp/cloud-api. Permissão: `read` (templates: `templates`).",
        "tags": [
          "whatsapp-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/whatsapp/cloud-api"
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "`phone_number_id` ou `messaging_account_id` de uma conexão da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, ex.: `messages`, `message_templates` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "mirrorPost",
        "summary": "Espelho da Meta (escrita)",
        "description": "Repassa um `POST` para a Graph API da Meta com o token da conexão. `POST …/messages` respeita o limite de mensagens por segundo do número, grava a mensagem e devolve o ID no cabeçalho `X-Messajo-Message-Id`. Caminhos que quebram a conexão (`register`, `deregister`, `request_code`, `verify_code`, `smb_app_data`, `subscribed_apps` com `override_callback_uri`) são recusados com `403 mirror_path_blocked`. Permissão: `send` para mensagens, `templates` para templates, `admin` para o resto.",
        "tags": [
          "whatsapp-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/whatsapp/cloud-api"
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "`phone_number_id` ou `messaging_account_id` de uma conexão da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, ex.: `messages`, `message_templates` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "description": "Corpo no formato da Graph API, repassado como está.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "mirrorDelete",
        "summary": "Espelho da Meta (exclusão)",
        "description": "Repassa um `DELETE` para a Graph API da Meta com o token da conexão. `DELETE …/subscribed_apps` é recusado (`403 mirror_path_blocked`). Permissão: `templates` para templates, `admin` para o resto.",
        "tags": [
          "whatsapp-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/whatsapp/cloud-api"
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "`phone_number_id` ou `messaging_account_id` de uma conexão da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, ex.: `messages`, `message_templates` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/instagram/{ig_user_id}/{path}": {
      "get": {
        "operationId": "instagramMirrorGet",
        "summary": "Espelho do Instagram (leitura)",
        "description": "Repassa um `GET` à Graph API do Instagram com o token da conta, sem mudar corpo nem resposta (erros da Meta voltam como a Meta mandou). `{ig_user_id}` é uma conta da organização; nós avulsos (mídia, comentário, contêiner) ficam em `{ig_user_id}/nodes/{node_id}`. Referência: https://developers.facebook.com/docs/instagram-platform. Permissão: `read`.",
        "tags": [
          "instagram-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/instagram-platform"
        },
        "parameters": [
          {
            "name": "ig_user_id",
            "in": "path",
            "required": true,
            "description": "`ig_user_id` de uma conta do Instagram da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, por exemplo `messages`, `media` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "instagramMirrorPost",
        "summary": "Espelho do Instagram (escrita)",
        "description": "Repassa um `POST` à Graph API do Instagram com o token da conta. `POST …/messages` respeita o limite de mensagens por segundo, grava a mensagem e devolve o ID no cabeçalho `X-Messajo-Message-Id`. `media_publish` pelo espelho não vira publicação agendável (use `POST /publications`). Caminhos que quebram a conexão (`subscribed_apps`, `access_token`, `oauth/*`) são recusados com `403 mirror_path_blocked`. Permissão: `send` para mensagens, mídia, publicação e comentários; `admin` para o resto.",
        "tags": [
          "instagram-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/instagram-platform"
        },
        "parameters": [
          {
            "name": "ig_user_id",
            "in": "path",
            "required": true,
            "description": "`ig_user_id` de uma conta do Instagram da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, por exemplo `messages`, `media` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "description": "Corpo no formato da Graph API, repassado como veio.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "instagramMirrorDelete",
        "summary": "Espelho do Instagram (exclusão)",
        "description": "Repassa um `DELETE` à Graph API do Instagram com o token da conta. Apagar comentário exige `send`; o resto, `admin`. `subscribed_apps` é recusado (`403 mirror_path_blocked`).",
        "tags": [
          "instagram-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/instagram-platform"
        },
        "parameters": [
          {
            "name": "ig_user_id",
            "in": "path",
            "required": true,
            "description": "`ig_user_id` de uma conta do Instagram da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, por exemplo `messages`, `media` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/messenger/{page_id}/{path}": {
      "get": {
        "operationId": "messengerMirrorGet",
        "summary": "Espelho do Messenger (leitura)",
        "description": "Repassa um `GET` à Graph API do Facebook com o token da Página, sem mudar corpo nem resposta. `{page_id}` é uma Página da organização; nós avulsos ficam em `{page_id}/nodes/{node_id}`. Referência: https://developers.facebook.com/docs/messenger-platform. Permissão: `read`.",
        "tags": [
          "messenger-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/messenger-platform"
        },
        "parameters": [
          {
            "name": "page_id",
            "in": "path",
            "required": true,
            "description": "`page_id` de uma Página do Facebook da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, por exemplo `messages`, `media` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "messengerMirrorPost",
        "summary": "Espelho do Messenger (escrita)",
        "description": "Repassa um `POST` à Graph API do Facebook com o token da Página. `POST …/messages` respeita o limite de mensagens por segundo, grava a mensagem e devolve o ID em `X-Messajo-Message-Id`. `subscribed_apps`, `access_token` e `oauth/*` são recusados (`403 mirror_path_blocked`); `pass_thread_control`/`take_thread_control` exigem `admin`. Permissão: `send` para mensagens e anexos, `admin` para o resto.",
        "tags": [
          "messenger-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/messenger-platform"
        },
        "parameters": [
          {
            "name": "page_id",
            "in": "path",
            "required": true,
            "description": "`page_id` de uma Página do Facebook da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, por exemplo `messages`, `media` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "description": "Corpo no formato da Graph API, repassado como veio.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "messengerMirrorDelete",
        "summary": "Espelho do Messenger (exclusão)",
        "description": "Repassa um `DELETE` à Graph API do Facebook com o token da Página. `subscribed_apps` é recusado (`403 mirror_path_blocked`). Permissão: `admin`.",
        "tags": [
          "messenger-mirror"
        ],
        "externalDocs": {
          "url": "https://developers.facebook.com/docs/messenger-platform"
        },
        "parameters": [
          {
            "name": "page_id",
            "in": "path",
            "required": true,
            "description": "`page_id` de uma Página do Facebook da organização.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto do caminho da Graph API, por exemplo `messages`, `media` ou `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A resposta da Meta, como veio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    }
  }
}
