{
  "info": {
    "title": "Messajo API",
    "version": "dev",
    "description": "API REST de Messajo para WhatsApp, Instagram y Messenger, sobre las APIs oficiales de Meta. Tiene dos capas: la API unificada (`/v1/*`), igual para los tres canales, y las rutas espejo de Meta (`/v1/whatsapp/{connection_id}/*`), que reenvían el formato de la Graph API. Toda llamada se autentica con una clave de API en el encabezado `Authorization: Bearer`. Guías, conceptos y ejemplos: https://docs.messajo.com.",
    "contact": {
      "url": "https://docs.messajo.com"
    }
  },
  "servers": [
    {
      "url": "https://api.messajo.com/v1",
      "description": "Messajo Cloud"
    }
  ],
  "tags": [
    {
      "name": "account",
      "description": "Cuenta: la organización y la clave de API de la llamada."
    },
    {
      "name": "destinations",
      "description": "Destinos: adónde Messajo envía los eventos (webhooks firmados)."
    },
    {
      "name": "deliveries",
      "description": "Entregas: cada intento de llevar un evento a un destino, con reenvío."
    },
    {
      "name": "events",
      "description": "Eventos: lo que pasó en las conexiones, en el mismo sobre que reciben los destinos (30 días)."
    },
    {
      "name": "logs",
      "description": "Logs: mensajes y llamadas a la API de los últimos 30 días."
    },
    {
      "name": "connections",
      "description": "Conexiones: los números conectados, su salud, perfil y nombre de usuario."
    },
    {
      "name": "messages",
      "description": "Mensajes: envío por la API unificada y marcado como leído."
    },
    {
      "name": "templates",
      "description": "Plantillas: plantillas de mensaje de WhatsApp aprobadas por Meta."
    },
    {
      "name": "media",
      "description": "Medios: archivos para enviar, descargar y compartir por enlace temporal."
    },
    {
      "name": "connection-links",
      "description": "Enlaces de conexión: páginas públicas para que alguien de fuera conecte un número."
    },
    {
      "name": "whatsapp-mirror",
      "description": "Espejo de Meta: la Graph API de WhatsApp reenviada con el token de la conexión."
    },
    {
      "name": "messaging-profile",
      "description": "Perfil de mensajes: ice breakers, menú fijo y bienvenida de Instagram y Messenger."
    },
    {
      "name": "comments",
      "description": "Comentarios y menciones de Instagram: listar, responder, responder por Direct, ocultar y borrar."
    },
    {
      "name": "posts",
      "description": "Publicaciones del feed de Instagram: lista, detalle y cuota de publicación."
    },
    {
      "name": "insights",
      "description": "Insights de Instagram: métricas de la cuenta y de cada post."
    },
    {
      "name": "publications",
      "description": "Publicaciones de Instagram: foto, video, carrusel, Reels y Stories, al momento o programadas."
    },
    {
      "name": "instagram-mirror",
      "description": "Espejo de Meta: la Graph API de Instagram reenviada con el token de la cuenta."
    },
    {
      "name": "messenger-mirror",
      "description": "Espejo de Meta: la Graph API de Messenger reenviada con el token de la Página."
    },
    {
      "name": "history",
      "description": "Historial: conversaciones, contactos y mensajes guardados, con filtros y paginación por cursor."
    },
    {
      "name": "campaigns",
      "description": "Campañas: envío masivo de plantillas de WhatsApp a una lista, con programación e informe."
    },
    {
      "name": "calls",
      "description": "Llamadas de WhatsApp (Calling API, solo señalización): registro, acciones, permiso de llamada y configuración del número."
    },
    {
      "name": "groups",
      "description": "Grupos de WhatsApp (Groups API): crear, invitar, moderar participantes y solicitudes de ingreso."
    },
    {
      "name": "flows",
      "description": "WhatsApp Flows: crear, editar el JSON, publicar, deprecar y previsualizar, con el endpoint de data exchange alojado por Messajo."
    },
    {
      "name": "commerce",
      "description": "Comercio en WhatsApp: catálogos, productos, configuración del carrito y pedidos con Pix, enlace de pago o boleto."
    },
    {
      "name": "usage",
      "description": "Uso y costos de Meta"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "mj_…",
        "description": "Clave de API creada en el panel (Configuración → Claves de API), enviada como `Authorization: Bearer mj_…`. La clave lleva permisos y, opcionalmente, la lista de conexiones que puede usar."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "description": "Cuerpo único de error: todo error de la API tiene 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 estable del error. Cada código tiene una sección en https://docs.messajo.com/errors."
              },
              "message": {
                "type": "string",
                "description": "Mensaje corto en inglés, para logs. No lo muestres al usuario final: traduce por el `code`."
              },
              "meta_code": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Código de error devuelto por Meta, cuando el error vino de ella; si no, `null`."
              },
              "retryable": {
                "type": "boolean",
                "description": "`true` cuando repetir la misma llamada más tarde puede funcionar."
              },
              "request_id": {
                "type": "string",
                "description": "ID de la solicitud, el mismo del encabezado `X-Request-Id`."
              },
              "docs_url": {
                "type": "string",
                "format": "uri",
                "description": "Enlace a la explicación del código en la documentación."
              },
              "retry_after_ms": {
                "type": "integer",
                "description": "Solo en `rate_limited`: cuánto esperar, en milisegundos, antes de repetir."
              },
              "details": {
                "type": "array",
                "description": "Solo en `validation_failed` (un elemento por campo inválido) y `destination_url_not_allowed` (el motivo en `message`).",
                "items": {
                  "type": "object",
                  "required": [
                    "path",
                    "message"
                  ],
                  "properties": {
                    "path": {
                      "type": "string",
                      "description": "Ruta del campo inválido, p. ej.: `to` o `items[0].id`."
                    },
                    "message": {
                      "type": "string",
                      "description": "Qué está mal en el campo."
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "headers": {
      "X-Request-Id": {
        "description": "ID único de la solicitud. Indícalo al soporte para encontrar la llamada en los logs.",
        "schema": {
          "type": "string"
        }
      },
      "X-RateLimit-Limit": {
        "description": "Solicitudes permitidas por minuto para esta clave.",
        "schema": {
          "type": "integer"
        }
      },
      "X-RateLimit-Remaining": {
        "description": "Solicitudes que quedan en la ventana actual.",
        "schema": {
          "type": "integer"
        }
      },
      "X-RateLimit-Reset": {
        "description": "Cuándo se reinicia la ventana actual (Unix epoch, en segundos).",
        "schema": {
          "type": "integer"
        }
      },
      "Retry-After": {
        "description": "Segundos que esperar antes de repetir la llamada.",
        "schema": {
          "type": "integer"
        }
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Clave única (8–255 caracteres `A-Z a-z 0-9 . _ : -`) para repetir un `POST` sin efecto duplicado. Vale 24 h por organización, método y ruta: la misma clave con el mismo cuerpo devuelve la respuesta guardada (cabecera `Idempotent-Replayed: true`); con otro cuerpo, `422 idempotency_key_reused`; mientras la primera se ejecuta, `409 idempotency_in_progress`.",
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{8,255}$"
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Entrada inválida (`validation_failed`): mira `details`.",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Clave ausente, inválida, vencida o desactivada (`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": "La clave no tiene el permiso exigido o no puede usar esta conexión (`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": "El recurso no existe o no pertenece a la organización (`not_found`).",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Se alcanzó el límite de solicitudes de la clave (`rate_limited`): espera `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": "Conflicto con el estado actual (`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": "La `Idempotency-Key` ya se usó con otro cuerpo (`idempotency_key_reused`).",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "InternalError": {
        "description": "Error inesperado del servidor (`internal_error`). Puedes repetir; si persiste, informa el `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 la clave actual",
        "description": "Devuelve la organización dueña de la clave y los datos de la propia clave (permisos, conexiones permitidas, vencimiento). Útil para probar la clave y saber qué puede hacer. Permiso: cualquier clave válida.",
        "tags": [
          "account"
        ],
        "responses": {
          "200": {
            "description": "La organización y la clave usadas en la llamada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "organization": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "ID de la organización.",
                          "examples": [
                            "Kq3vT9xZ2mWb7LpR4nYc8sDf1gHj6aEu"
                          ]
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la organización.",
                          "examples": [
                            "Acme"
                          ]
                        },
                        "slug": {
                          "type": "string",
                          "description": "Identificador corto de la organización, usado en URLs.",
                          "examples": [
                            "acme"
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "slug"
                      ],
                      "description": "Organización dueña de la clave."
                    },
                    "api_key": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "ID de la clave.",
                          "examples": [
                            "Zt5rB8wQ1nXc4LmV7pYd2sGf9hJk3aRe"
                          ]
                        },
                        "name": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Nombre dado a la clave en el panel.",
                          "examples": [
                            "production"
                          ]
                        },
                        "start": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Inicio de la clave, para reconocerla sin exponer el secreto.",
                          "examples": [
                            "mj_A1b2c3d"
                          ]
                        },
                        "permissions": {
                          "type": "array",
                          "items": {
                            "enum": [
                              "send",
                              "read",
                              "templates",
                              "commerce",
                              "admin"
                            ],
                            "type": "string"
                          },
                          "description": "Permisos de la clave: `send`, `read`, `templates` o `admin` (incluye los demás).",
                          "examples": [
                            [
                              "read"
                            ]
                          ]
                        },
                        "connection_ids": {
                          "anyOf": [
                            {
                              "type": "array",
                              "items": {
                                "type": "string"
                              }
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Conexiones que la clave puede usar; `null` = todas las conexiones de la organización.",
                          "examples": [
                            null
                          ]
                        },
                        "kind": {
                          "enum": [
                            "org",
                            "connection"
                          ],
                          "type": "string",
                          "description": "Tipo de clave: `org` (toda la organización) o `connection` (atada a una conexión).",
                          "examples": [
                            "org"
                          ]
                        },
                        "connection_id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Conexión a la que la clave está atada; `null` en claves de organización.",
                          "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": "Conexión a la que está ligada la clave (`id`, `channel`, `label`); `null` en claves de organización.",
                          "examples": [
                            null
                          ]
                        },
                        "expires_at": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Fecha de vencimiento (ISO 8601, UTC); `null` = no vence.",
                          "examples": [
                            "2027-01-01T00:00:00.000Z"
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "start",
                        "permissions",
                        "connection_ids",
                        "kind",
                        "connection_id",
                        "connection",
                        "expires_at"
                      ],
                      "description": "La clave usada en la llamada."
                    },
                    "request_id": {
                      "type": "string",
                      "description": "ID de esta solicitud, el mismo del encabezado `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 los destinos de eventos de la organización. Una clave limitada a conexiones solo ve los destinos limitados a ellas. Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "responses": {
          "200": {
            "description": "Los destinos de la organización.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del destino.",
                            "examples": [
                              "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "type": {
                            "enum": [
                              "webhook",
                              "rabbitmq",
                              "sqs",
                              "kafka",
                              "websocket"
                            ],
                            "type": "string",
                            "description": "Tipo del destino: `webhook` (por defecto), `rabbitmq`, `sqs`, `kafka` o `websocket`. Tipo desactivado en el servidor → `422 destination_type_disabled`. No cambia después de creado."
                          },
                          "label": {
                            "type": "string",
                            "description": "Nombre del destino, para reconocerlo.",
                            "examples": [
                              "CRM"
                            ]
                          },
                          "url": {
                            "type": "string",
                            "description": "URL `https` que recibe los eventos por `POST`.",
                            "examples": [
                              "https://example.com/webhooks/messajo"
                            ]
                          },
                          "headers": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "name": {
                                  "type": "string",
                                  "description": "Nombre de la cabecera."
                                },
                                "value_last4": {
                                  "type": "string",
                                  "description": "Últimos 4 caracteres del valor de la cabecera."
                                }
                              },
                              "required": [
                                "name",
                                "value_last4"
                              ]
                            },
                            "description": "Cabeceras propias enviadas en cada entrega (hasta 20). No pueden sobrescribir las `Messajo-*`."
                          },
                          "format": {
                            "enum": [
                              "normalized",
                              "meta"
                            ],
                            "type": "string",
                            "description": "Formato de `data`: `normalized` (igual en los tres canales) o `meta` (el elemento original de Meta, cuando existe)."
                          },
                          "event_types": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Patrones de tipo de evento: tipo exacto (`message.received`), familia (`message.*`) o `*`.",
                            "examples": [
                              [
                                "message.*"
                              ]
                            ]
                          },
                          "connection_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conexión dueña del destino (`con_…`); `null` = destino global de la organización, que recibe eventos de todas las conexiones. No cambia después de creado."
                          },
                          "connection_ids": {
                            "anyOf": [
                              {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Obsoleto: usa `connection_id`. Acepta `null` o una sola conexión; más de una → `400 validation_failed`. En la respuesta se deriva de `connection_id` (`[id]` o `null`)."
                          },
                          "status": {
                            "enum": [
                              "active",
                              "paused",
                              "auto_paused"
                            ],
                            "type": "string",
                            "description": "`active`, `paused` (manual) o `auto_paused` (fallos seguidos durante 24 h)."
                          },
                          "paused_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo de la pausa (`manual` o `failing`); `null` con el destino activo."
                          },
                          "secret_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres del secreto de firma actual."
                          },
                          "previous_secret_expires_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Hasta cuándo el secreto anterior también firma (ISO 8601, UTC); `null` = sin secreto anterior.",
                            "examples": [
                              null
                            ]
                          },
                          "failing_since": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Desde cuándo las entregas fallan sin parar (ISO 8601, UTC); `null` = sin fallo en curso.",
                            "examples": [
                              null
                            ]
                          },
                          "last_success_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última entrega con éxito (ISO 8601, UTC); se actualiza como máximo cada 30 s.",
                            "examples": [
                              null
                            ]
                          },
                          "last_failure_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última entrega fallida (ISO 8601, UTC).",
                            "examples": [
                              null
                            ]
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Fecha de creación (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Fecha del último cambio (ISO 8601, UTC)."
                          },
                          "config": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {},
                            "description": "Bloque del tipo, sin secretos (las contraseñas se vuelven `password_last4`). `{}` en webhook y con el tipo desactivado."
                          },
                          "connected_clients": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Clientes WebSocket conectados ahora; `null` fuera del 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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Crear destino",
        "description": "Crea un destino webhook. La URL debe ser `https` pública (las direcciones internas se rechazan con `destination_url_not_allowed`). El secreto de firma solo viene en esta respuesta: guárdalo. Máximo 20 destinos por organización. Con clave de conexión, `connection_id` asume la conexión de la clave; `connection_id: null` (global) exige clave de la organización (`organization_key_required`). Permiso: `admin`. Los otros tipos (`rabbitmq`, `sqs`, `kafka`, `websocket`) van en el campo con el nombre del tipo, cuando están activados en el servidor; si no, `422 destination_type_disabled`.",
        "tags": [
          "destinations"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Nombre del destino, para reconocerlo."
                  },
                  "url": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2048,
                    "description": "URL `https` que recibe los eventos por `POST`."
                  },
                  "headers": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Nombre de la cabecera."
                        },
                        "value": {
                          "type": "string",
                          "maxLength": 4096,
                          "description": "Valor de la cabecera. Se guarda cifrado y nunca vuelve entero."
                        }
                      },
                      "required": [
                        "name",
                        "value"
                      ]
                    },
                    "description": "Cabeceras propias enviadas en cada entrega (hasta 20). No pueden sobrescribir las `Messajo-*`."
                  },
                  "format": {
                    "enum": [
                      "normalized",
                      "meta"
                    ],
                    "type": "string",
                    "description": "Formato de `data`: `normalized` (igual en los tres canales) o `meta` (el elemento original de Meta, cuando existe)."
                  },
                  "event_types": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Patrones de tipo de evento: tipo exacto (`message.received`), familia (`message.*`) o `*`."
                  },
                  "connection_ids": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Obsoleto: usa `connection_id`. Acepta `null` o una sola conexión; más de una → `400 validation_failed`. En la respuesta se deriva de `connection_id` (`[id]` o `null`)."
                  },
                  "type": {
                    "enum": [
                      "webhook",
                      "rabbitmq",
                      "sqs",
                      "kafka",
                      "websocket"
                    ],
                    "type": "string",
                    "default": "webhook",
                    "description": "Tipo del destino: `webhook` (por defecto), `rabbitmq`, `sqs`, `kafka` o `websocket`. Tipo desactivado en el servidor → `422 destination_type_disabled`. No cambia después de creado."
                  },
                  "connection_id": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Conexión dueña del destino (`con_…`); `null` = destino global de la organización, que recibe eventos de todas las conexiones. No cambia después de creado."
                  },
                  "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": "Solo con `type: rabbitmq`: `url` (`amqps://usuario:contraseña@host:5671/vhost`), `exchange`, `routing_key` (por defecto `messajo.{type}`) y `persistent` (por defecto `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": "Solo con `type: sqs`: `queue_url`, `region`, `access_key_id`, `secret_access_key`, `session_token` opcional y `message_group_id` (colas `.fifo`, por defecto `{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": "Solo con `type: kafka`: `brokers` (hasta 10), `topic`, `ssl` (por defecto `true`), `sasl` (`plain`, `scram-sha-256` o `scram-sha-512`), `key` (por defecto `{connection}`) y `client_id`."
                  },
                  "websocket": {
                    "type": "object",
                    "additionalProperties": false,
                    "description": "Solo con `type: websocket`: objeto vacío. Los eventos llegan en `GET /v1/ws` y el cliente confirma cada uno con `ack`."
                  }
                },
                "required": [
                  "label",
                  "format",
                  "event_types"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El destino creado, con el secreto de firma.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo del destino: `webhook` (por defecto), `rabbitmq`, `sqs`, `kafka` o `websocket`. Tipo desactivado en el servidor → `422 destination_type_disabled`. No cambia después de creado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del destino, para reconocerlo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recibe los eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nombre de la cabecera."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres del valor de la cabecera."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeceras propias enviadas en cada entrega (hasta 20). No pueden sobrescribir las `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato de `data`: `normalized` (igual en los tres canales) o `meta` (el elemento original de Meta, cuando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Patrones de tipo de evento: tipo exacto (`message.received`), familia (`message.*`) o `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión dueña del destino (`con_…`); `null` = destino global de la organización, que recibe eventos de todas las conexiones. No cambia después de creado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: usa `connection_id`. Acepta `null` o una sola conexión; más de una → `400 validation_failed`. En la respuesta se deriva de `connection_id` (`[id]` o `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) o `auto_paused` (fallos seguidos durante 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo de la pausa (`manual` o `failing`); `null` con el destino activo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del secreto de firma actual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hasta cuándo el secreto anterior también firma (ISO 8601, UTC); `null` = sin secreto anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde cuándo las entregas fallan sin parar (ISO 8601, UTC); `null` = sin fallo en curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega con éxito (ISO 8601, UTC); se actualiza como máximo cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega fallida (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Fecha del último cambio (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloque del tipo, sin secretos (las contraseñas se vuelven `password_last4`). `{}` en webhook y con el tipo desactivado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados ahora; `null` fuera del tipo `websocket`."
                    },
                    "secret": {
                      "type": "string",
                      "description": "Secreto de firma (`whsec_…`). Solo aparece en esta respuesta: guárdalo para verificar `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": "Devuelve un destino. Los valores de las cabeceras propias salen enmascarados. Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del destino."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El destino.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo del destino: `webhook` (por defecto), `rabbitmq`, `sqs`, `kafka` o `websocket`. Tipo desactivado en el servidor → `422 destination_type_disabled`. No cambia después de creado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del destino, para reconocerlo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recibe los eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nombre de la cabecera."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres del valor de la cabecera."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeceras propias enviadas en cada entrega (hasta 20). No pueden sobrescribir las `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato de `data`: `normalized` (igual en los tres canales) o `meta` (el elemento original de Meta, cuando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Patrones de tipo de evento: tipo exacto (`message.received`), familia (`message.*`) o `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión dueña del destino (`con_…`); `null` = destino global de la organización, que recibe eventos de todas las conexiones. No cambia después de creado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: usa `connection_id`. Acepta `null` o una sola conexión; más de una → `400 validation_failed`. En la respuesta se deriva de `connection_id` (`[id]` o `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) o `auto_paused` (fallos seguidos durante 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo de la pausa (`manual` o `failing`); `null` con el destino activo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del secreto de firma actual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hasta cuándo el secreto anterior también firma (ISO 8601, UTC); `null` = sin secreto anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde cuándo las entregas fallan sin parar (ISO 8601, UTC); `null` = sin fallo en curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega con éxito (ISO 8601, UTC); se actualiza como máximo cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega fallida (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Fecha del último cambio (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloque del tipo, sin secretos (las contraseñas se vuelven `password_last4`). `{}` en webhook y con el tipo desactivado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados ahora; `null` fuera del 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": "Modificar destino",
        "description": "Cambia los campos enviados; los ausentes quedan como están. El secreto no cambia aquí: usa `rotate-secret`. Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del destino."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Nombre del destino, para reconocerlo."
                  },
                  "url": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2048,
                    "description": "URL `https` que recibe los eventos por `POST`."
                  },
                  "headers": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Nombre de la cabecera."
                        },
                        "value": {
                          "type": "string",
                          "maxLength": 4096,
                          "description": "Valor de la cabecera. Se guarda cifrado y nunca vuelve entero."
                        }
                      },
                      "required": [
                        "name",
                        "value"
                      ]
                    },
                    "description": "Cabeceras propias enviadas en cada entrega (hasta 20). No pueden sobrescribir las `Messajo-*`."
                  },
                  "format": {
                    "enum": [
                      "normalized",
                      "meta"
                    ],
                    "type": "string",
                    "description": "Formato de `data`: `normalized` (igual en los tres canales) o `meta` (el elemento original de Meta, cuando existe)."
                  },
                  "event_types": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Patrones de tipo de evento: tipo exacto (`message.received`), familia (`message.*`) o `*`."
                  },
                  "connection_id": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Conexión dueña del destino (`con_…`); `null` = destino global de la organización, que recibe eventos de todas las conexiones. No cambia después de creado."
                  },
                  "connection_ids": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Obsoleto: usa `connection_id`. Acepta `null` o una sola conexión; más de una → `400 validation_failed`. En la respuesta se deriva de `connection_id` (`[id]` o `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": "Solo con `type: rabbitmq`: `url` (`amqps://usuario:contraseña@host:5671/vhost`), `exchange`, `routing_key` (por defecto `messajo.{type}`) y `persistent` (por defecto `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": "Solo con `type: sqs`: `queue_url`, `region`, `access_key_id`, `secret_access_key`, `session_token` opcional y `message_group_id` (colas `.fifo`, por defecto `{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": "Solo con `type: kafka`: `brokers` (hasta 10), `topic`, `ssl` (por defecto `true`), `sasl` (`plain`, `scram-sha-256` o `scram-sha-512`), `key` (por defecto `{connection}`) y `client_id`."
                  },
                  "websocket": {
                    "type": "object",
                    "additionalProperties": false,
                    "description": "Solo con `type: websocket`: objeto vacío. Los eventos llegan en `GET /v1/ws` y el cliente confirma cada uno con `ack`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El destino modificado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo del destino: `webhook` (por defecto), `rabbitmq`, `sqs`, `kafka` o `websocket`. Tipo desactivado en el servidor → `422 destination_type_disabled`. No cambia después de creado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del destino, para reconocerlo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recibe los eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nombre de la cabecera."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres del valor de la cabecera."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeceras propias enviadas en cada entrega (hasta 20). No pueden sobrescribir las `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato de `data`: `normalized` (igual en los tres canales) o `meta` (el elemento original de Meta, cuando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Patrones de tipo de evento: tipo exacto (`message.received`), familia (`message.*`) o `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión dueña del destino (`con_…`); `null` = destino global de la organización, que recibe eventos de todas las conexiones. No cambia después de creado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: usa `connection_id`. Acepta `null` o una sola conexión; más de una → `400 validation_failed`. En la respuesta se deriva de `connection_id` (`[id]` o `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) o `auto_paused` (fallos seguidos durante 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo de la pausa (`manual` o `failing`); `null` con el destino activo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del secreto de firma actual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hasta cuándo el secreto anterior también firma (ISO 8601, UTC); `null` = sin secreto anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde cuándo las entregas fallan sin parar (ISO 8601, UTC); `null` = sin fallo en curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega con éxito (ISO 8601, UTC); se actualiza como máximo cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega fallida (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Fecha del último cambio (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloque del tipo, sin secretos (las contraseñas se vuelven `password_last4`). `{}` en webhook y con el tipo desactivado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados ahora; `null` fuera del 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": "Eliminar destino",
        "description": "Elimina el destino y su historial de entregas. Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del destino."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmación de la eliminación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del destino."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `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": "Cambiar secreto",
        "description": "Genera un secreto de firma nuevo. El anterior sigue firmando junto durante `keep_previous_hours` (0 a 72, por defecto 24), para cambiar sin perder entregas. Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del 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": "Durante cuántas horas el secreto anterior sigue firmando (0 a 72)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El secreto nuevo y hasta cuándo vale el anterior.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "secret": {
                      "type": "string",
                      "description": "Secreto de firma (`whsec_…`). Solo aparece en esta respuesta: guárdalo para verificar `Messajo-Signature`."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hasta cuándo el secreto anterior también firma (ISO 8601, UTC); `null` = sin secreto 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": "Deja de entregar al destino. Los eventos nuevos generan entregas fallidas con `destination_paused`, que se pueden reenviar después. Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "El destino pausado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo del destino: `webhook` (por defecto), `rabbitmq`, `sqs`, `kafka` o `websocket`. Tipo desactivado en el servidor → `422 destination_type_disabled`. No cambia después de creado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del destino, para reconocerlo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recibe los eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nombre de la cabecera."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres del valor de la cabecera."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeceras propias enviadas en cada entrega (hasta 20). No pueden sobrescribir las `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato de `data`: `normalized` (igual en los tres canales) o `meta` (el elemento original de Meta, cuando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Patrones de tipo de evento: tipo exacto (`message.received`), familia (`message.*`) o `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión dueña del destino (`con_…`); `null` = destino global de la organización, que recibe eventos de todas las conexiones. No cambia después de creado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: usa `connection_id`. Acepta `null` o una sola conexión; más de una → `400 validation_failed`. En la respuesta se deriva de `connection_id` (`[id]` o `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) o `auto_paused` (fallos seguidos durante 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo de la pausa (`manual` o `failing`); `null` con el destino activo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del secreto de firma actual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hasta cuándo el secreto anterior también firma (ISO 8601, UTC); `null` = sin secreto anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde cuándo las entregas fallan sin parar (ISO 8601, UTC); `null` = sin fallo en curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega con éxito (ISO 8601, UTC); se actualiza como máximo cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega fallida (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Fecha del último cambio (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloque del tipo, sin secretos (las contraseñas se vuelven `password_last4`). `{}` en webhook y con el tipo desactivado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados ahora; `null` fuera del 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": "Reanudar destino",
        "description": "Vuelve a entregar al destino (también tras una pausa automática). Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "El destino activo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del destino.",
                      "examples": [
                        "dst_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "enum": [
                        "webhook",
                        "rabbitmq",
                        "sqs",
                        "kafka",
                        "websocket"
                      ],
                      "type": "string",
                      "description": "Tipo del destino: `webhook` (por defecto), `rabbitmq`, `sqs`, `kafka` o `websocket`. Tipo desactivado en el servidor → `422 destination_type_disabled`. No cambia después de creado."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del destino, para reconocerlo.",
                      "examples": [
                        "CRM"
                      ]
                    },
                    "url": {
                      "type": "string",
                      "description": "URL `https` que recibe los eventos por `POST`.",
                      "examples": [
                        "https://example.com/webhooks/messajo"
                      ]
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "Nombre de la cabecera."
                          },
                          "value_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres del valor de la cabecera."
                          }
                        },
                        "required": [
                          "name",
                          "value_last4"
                        ]
                      },
                      "description": "Cabeceras propias enviadas en cada entrega (hasta 20). No pueden sobrescribir las `Messajo-*`."
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato de `data`: `normalized` (igual en los tres canales) o `meta` (el elemento original de Meta, cuando existe)."
                    },
                    "event_types": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Patrones de tipo de evento: tipo exacto (`message.received`), familia (`message.*`) o `*`.",
                      "examples": [
                        [
                          "message.*"
                        ]
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión dueña del destino (`con_…`); `null` = destino global de la organización, que recibe eventos de todas las conexiones. No cambia después de creado."
                    },
                    "connection_ids": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Obsoleto: usa `connection_id`. Acepta `null` o una sola conexión; más de una → `400 validation_failed`. En la respuesta se deriva de `connection_id` (`[id]` o `null`)."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "paused",
                        "auto_paused"
                      ],
                      "type": "string",
                      "description": "`active`, `paused` (manual) o `auto_paused` (fallos seguidos durante 24 h)."
                    },
                    "paused_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo de la pausa (`manual` o `failing`); `null` con el destino activo."
                    },
                    "secret_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del secreto de firma actual."
                    },
                    "previous_secret_expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hasta cuándo el secreto anterior también firma (ISO 8601, UTC); `null` = sin secreto anterior.",
                      "examples": [
                        null
                      ]
                    },
                    "failing_since": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Desde cuándo las entregas fallan sin parar (ISO 8601, UTC); `null` = sin fallo en curso.",
                      "examples": [
                        null
                      ]
                    },
                    "last_success_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega con éxito (ISO 8601, UTC); se actualiza como máximo cada 30 s.",
                      "examples": [
                        null
                      ]
                    },
                    "last_failure_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última entrega fallida (ISO 8601, UTC).",
                      "examples": [
                        null
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Fecha del último cambio (ISO 8601, UTC)."
                    },
                    "config": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Bloque del tipo, sin secretos (las contraseñas se vuelven `password_last4`). `{}` en webhook y con el tipo desactivado."
                    },
                    "connected_clients": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Clientes WebSocket conectados ahora; `null` fuera del 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": "Probar destino",
        "description": "Envía ahora un evento `destination.test` al destino y espera la respuesta (hasta 10 s, sin reintentos). Funciona con el destino pausado. Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La entrega de prueba, con el resultado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la entrega.",
                      "examples": [
                        "dlv_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "destination_id": {
                      "type": "string",
                      "description": "Destino de la entrega."
                    },
                    "event_id": {
                      "type": "string",
                      "description": "Evento entregado."
                    },
                    "event_type": {
                      "type": "string",
                      "description": "Tipo del evento.",
                      "examples": [
                        "message.received"
                      ]
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "retrying",
                        "succeeded",
                        "failed",
                        "canceled",
                        "held"
                      ],
                      "type": "string",
                      "description": "`pending`, `retrying` (volverá a intentar), `succeeded`, `failed` o `held` (organización suspendida)."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Intentos hechos hasta ahora."
                    },
                    "next_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Próximo intento (ISO 8601, UTC); `null` si no habrá otro."
                    },
                    "last_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último intento (ISO 8601, UTC)."
                    },
                    "last_status_code": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado HTTP de la última respuesta del destino; `null` sin respuesta (red, timeout)."
                    },
                    "last_error": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del último fallo."
                    },
                    "last_duration_ms": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración del último intento, en milisegundos."
                    },
                    "redelivery_of": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Entrega original, cuando esta es un reenvío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "succeeded_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la entrega tuvo éxito (ISO 8601, UTC)."
                    },
                    "failed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la entrega falló definitivamente (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 fallos",
        "description": "Reenvía las entregas fallidas del destino en el intervalo, hasta 1000 por llamada (`has_more` indica si quedan). El destino debe estar activo. Permiso: `admin`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "since": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Inicio del intervalo (ISO 8601)."
                  },
                  "until": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Fin del intervalo (ISO 8601); ausente = ahora."
                  }
                },
                "required": [
                  "since"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cuántas entregas se volvieron a encolar.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "queued": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Entregas encoladas de nuevo en esta llamada."
                    },
                    "has_more": {
                      "type": "boolean",
                      "description": "`true` si quedan fallos en el intervalo: vuelve a llamar."
                    }
                  },
                  "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": "Crear ticket de WebSocket",
        "description": "Genera un ticket de un solo uso, válido por 60 s, para abrir `GET /v1/ws?ticket=…` en un destino `websocket` activo (navegadores sin cabecera `Authorization`). Permiso: `read`.",
        "tags": [
          "destinations"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del destino."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "El ticket y la URL de conexión.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ticket": {
                      "type": "string",
                      "description": "Ticket de un solo uso (`wst_…`), válido por 60 s."
                    },
                    "url": {
                      "type": "string",
                      "description": "URL lista para abrir el WebSocket con el ticket."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Cuándo vence el ticket (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 las entregas de eventos a los destinos (30 días), de la más nueva a la más antigua. Permiso: `read`.",
        "tags": [
          "deliveries"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "destination_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Destino de la entrega."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending",
                "retrying",
                "succeeded",
                "failed",
                "canceled",
                "held"
              ],
              "type": "string",
              "description": "`pending`, `retrying` (volverá a intentar), `succeeded`, `failed` o `held` (organización suspendida)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "event_type",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Tipo del evento."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Solo entregas creadas a partir de esta fecha (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Solo entregas creadas hasta esta fecha (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Las entregas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la entrega.",
                            "examples": [
                              "dlv_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "destination_id": {
                            "type": "string",
                            "description": "Destino de la entrega."
                          },
                          "event_id": {
                            "type": "string",
                            "description": "Evento entregado."
                          },
                          "event_type": {
                            "type": "string",
                            "description": "Tipo del evento.",
                            "examples": [
                              "message.received"
                            ]
                          },
                          "status": {
                            "enum": [
                              "pending",
                              "retrying",
                              "succeeded",
                              "failed",
                              "canceled",
                              "held"
                            ],
                            "type": "string",
                            "description": "`pending`, `retrying` (volverá a intentar), `succeeded`, `failed` o `held` (organización suspendida)."
                          },
                          "attempts": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Intentos hechos hasta ahora."
                          },
                          "next_attempt_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Próximo intento (ISO 8601, UTC); `null` si no habrá otro."
                          },
                          "last_attempt_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último intento (ISO 8601, UTC)."
                          },
                          "last_status_code": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Estado HTTP de la última respuesta del destino; `null` sin respuesta (red, timeout)."
                          },
                          "last_error": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo del último fallo."
                          },
                          "last_duration_ms": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Duración del último intento, en milisegundos."
                          },
                          "redelivery_of": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Entrega original, cuando esta es un reenvío."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Fecha de creación (ISO 8601, UTC)."
                          },
                          "succeeded_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo la entrega tuvo éxito (ISO 8601, UTC)."
                          },
                          "failed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo la entrega falló definitivamente (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Devuelve una entrega con el registro de sus últimos 20 intentos. Permiso: `read`.",
        "tags": [
          "deliveries"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la entrega."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La entrega y sus intentos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la entrega.",
                      "examples": [
                        "dlv_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "destination_id": {
                      "type": "string",
                      "description": "Destino de la entrega."
                    },
                    "event_id": {
                      "type": "string",
                      "description": "Evento entregado."
                    },
                    "event_type": {
                      "type": "string",
                      "description": "Tipo del evento.",
                      "examples": [
                        "message.received"
                      ]
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "retrying",
                        "succeeded",
                        "failed",
                        "canceled",
                        "held"
                      ],
                      "type": "string",
                      "description": "`pending`, `retrying` (volverá a intentar), `succeeded`, `failed` o `held` (organización suspendida)."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Intentos hechos hasta ahora."
                    },
                    "next_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Próximo intento (ISO 8601, UTC); `null` si no habrá otro."
                    },
                    "last_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último intento (ISO 8601, UTC)."
                    },
                    "last_status_code": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado HTTP de la última respuesta del destino; `null` sin respuesta (red, timeout)."
                    },
                    "last_error": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del último fallo."
                    },
                    "last_duration_ms": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración del último intento, en milisegundos."
                    },
                    "redelivery_of": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Entrega original, cuando esta es un reenvío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "succeeded_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la entrega tuvo éxito (ISO 8601, UTC)."
                    },
                    "failed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la entrega falló definitivamente (ISO 8601, UTC)."
                    },
                    "attempt_log": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "n": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Número del intento (1 = primero)."
                          },
                          "at": {
                            "type": "string",
                            "description": "Cuándo se hizo el intento (ISO 8601, UTC)."
                          },
                          "status_code": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Estado HTTP de la respuesta; `null` sin respuesta."
                          },
                          "duration_ms": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Duración del intento, en milisegundos."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo del fallo; `null` con éxito."
                          },
                          "response_excerpt": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Inicio del cuerpo de la respuesta (hasta 1 KiB)."
                          }
                        },
                        "required": [
                          "n",
                          "at",
                          "status_code",
                          "duration_ms",
                          "error",
                          "response_excerpt"
                        ]
                      },
                      "description": "Últimos 20 intentos."
                    }
                  },
                  "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": "Crea una entrega nueva del mismo evento para el mismo destino. El destino debe estar activo. Permiso: `admin`.",
        "tags": [
          "deliveries"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la entrega."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "La entrega nueva.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la entrega.",
                      "examples": [
                        "dlv_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "destination_id": {
                      "type": "string",
                      "description": "Destino de la entrega."
                    },
                    "event_id": {
                      "type": "string",
                      "description": "Evento entregado."
                    },
                    "event_type": {
                      "type": "string",
                      "description": "Tipo del evento.",
                      "examples": [
                        "message.received"
                      ]
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "retrying",
                        "succeeded",
                        "failed",
                        "canceled",
                        "held"
                      ],
                      "type": "string",
                      "description": "`pending`, `retrying` (volverá a intentar), `succeeded`, `failed` o `held` (organización suspendida)."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Intentos hechos hasta ahora."
                    },
                    "next_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Próximo intento (ISO 8601, UTC); `null` si no habrá otro."
                    },
                    "last_attempt_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último intento (ISO 8601, UTC)."
                    },
                    "last_status_code": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado HTTP de la última respuesta del destino; `null` sin respuesta (red, timeout)."
                    },
                    "last_error": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del último fallo."
                    },
                    "last_duration_ms": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración del último intento, en milisegundos."
                    },
                    "redelivery_of": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Entrega original, cuando esta es un reenvío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "succeeded_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la entrega tuvo éxito (ISO 8601, UTC)."
                    },
                    "failed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la entrega falló definitivamente (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 los eventos de los últimos 30 días en el mismo sobre que reciben los destinos. Una clave limitada a conexiones solo ve los eventos de ellas. Permiso: `read`.",
        "tags": [
          "events"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Tipo del evento, p. ej. `message.received`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Solo eventos de esta conexión."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Solo eventos guardados a partir de esta fecha (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "enum": [
                "normalized",
                "meta"
              ],
              "type": "string",
              "default": "normalized",
              "description": "Formato de `data`: `normalized` (por defecto) o `meta`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Los eventos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del evento (igual a la cabecera `Messajo-Event-Id`).",
                            "examples": [
                              "evt_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "type": {
                            "type": "string",
                            "description": "Tipo del evento, p. ej. `message.received`.",
                            "examples": [
                              "message.received"
                            ]
                          },
                          "format": {
                            "enum": [
                              "normalized",
                              "meta"
                            ],
                            "type": "string",
                            "description": "Formato usado en `data`. Un evento sin elemento de Meta (p. ej. `message.sent`) sale `normalized` aunque se pida `meta`."
                          },
                          "org": {
                            "type": "string",
                            "description": "Organización del evento."
                          },
                          "connection": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conexión del evento; `null` en eventos de la organización (p. ej. `destination.test`)."
                          },
                          "channel": {
                            "anyOf": [
                              {
                                "enum": [
                                  "whatsapp",
                                  "instagram",
                                  "messenger"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Canal de la conexión: `whatsapp`, `instagram` o `messenger`; `null` en eventos de la organización."
                          },
                          "timestamp": {
                            "type": "string",
                            "description": "Cuándo ocurrió el hecho (ISO 8601, UTC)."
                          },
                          "sequence": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Orden del evento en la conversación (crece de 1 en 1); `null` en eventos fuera de una conversación."
                          },
                          "data": {
                            "description": "Datos del evento, en el formato de `format`."
                          }
                        },
                        "required": [
                          "id",
                          "type",
                          "format",
                          "org",
                          "connection",
                          "channel",
                          "timestamp",
                          "sequence"
                        ]
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Devuelve un evento en el sobre de entrega, en el formato pedido. Permiso: `read`.",
        "tags": [
          "events"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del evento (igual a la cabecera `Messajo-Event-Id`)."
            }
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "enum": [
                "normalized",
                "meta"
              ],
              "type": "string",
              "default": "normalized",
              "description": "Formato de `data`: `normalized` (por defecto) o `meta`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "El evento.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del evento (igual a la cabecera `Messajo-Event-Id`).",
                      "examples": [
                        "evt_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "type": {
                      "type": "string",
                      "description": "Tipo del evento, p. ej. `message.received`.",
                      "examples": [
                        "message.received"
                      ]
                    },
                    "format": {
                      "enum": [
                        "normalized",
                        "meta"
                      ],
                      "type": "string",
                      "description": "Formato usado en `data`. Un evento sin elemento de Meta (p. ej. `message.sent`) sale `normalized` aunque se pida `meta`."
                    },
                    "org": {
                      "type": "string",
                      "description": "Organización del evento."
                    },
                    "connection": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión del evento; `null` en eventos de la organización (p. ej. `destination.test`)."
                    },
                    "channel": {
                      "anyOf": [
                        {
                          "enum": [
                            "whatsapp",
                            "instagram",
                            "messenger"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Canal de la conexión: `whatsapp`, `instagram` o `messenger`; `null` en eventos de la organización."
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "Cuándo ocurrió el hecho (ISO 8601, UTC)."
                    },
                    "sequence": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Orden del evento en la conversación (crece de 1 en 1); `null` en eventos fuera de una conversación."
                    },
                    "data": {
                      "description": "Datos del evento, en el 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 mensajes",
        "description": "Lista los mensajes recibidos y enviados en los últimos 30 días, sin el contenido. Un `since` de más de 30 días devuelve `validation_failed`. Permiso: `read`.",
        "tags": [
          "logs"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Conexión del mensaje."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "enum": [
                "inbound",
                "outbound"
              ],
              "type": "string",
              "description": "`inbound` (recibido) o `outbound` (enviado)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "received",
                "queued",
                "sent",
                "delivered",
                "read",
                "played",
                "failed",
                "deleted"
              ],
              "type": "string",
              "description": "Estado actual del mensaje."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Tipo del contenido, p. ej. `text`, `image`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Inicio del intervalo (ISO 8601), como máximo hace 30 días; por defecto = hace 30 días."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fin del intervalo (ISO 8601); por defecto = ahora."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Los mensajes.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del mensaje."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se guardó el mensaje (ISO 8601, UTC)."
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "Conexión del mensaje."
                          },
                          "conversation_id": {
                            "type": "string",
                            "description": "Conversación del mensaje."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Contacto de la conversación."
                          },
                          "direction": {
                            "enum": [
                              "inbound",
                              "outbound"
                            ],
                            "type": "string",
                            "description": "`inbound` (recibido) o `outbound` (enviado)."
                          },
                          "source": {
                            "enum": [
                              "customer",
                              "api",
                              "business_app",
                              "history",
                              "campaign"
                            ],
                            "type": "string",
                            "description": "Origen: `customer`, `api`, `business_app`, `history` o `campaign`."
                          },
                          "type": {
                            "type": "string",
                            "description": "Tipo del contenido, p. ej. `text`, `image`."
                          },
                          "status": {
                            "enum": [
                              "received",
                              "queued",
                              "sent",
                              "delivered",
                              "read",
                              "played",
                              "failed",
                              "deleted"
                            ],
                            "type": "string",
                            "description": "Estado actual del mensaje."
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del mensaje en Meta."
                          },
                          "occurred_at": {
                            "type": "string",
                            "description": "Cuándo Meta registró el mensaje (ISO 8601, UTC)."
                          },
                          "status_updated_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último cambio de estado (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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 llamadas a la API",
        "description": "Lista las llamadas a `/v1` hechas con las claves de la organización en los últimos 30 días. Una clave limitada a conexiones solo ve sus propias llamadas. Permiso: `read`.",
        "tags": [
          "logs"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "api_key_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Clave usada en la llamada."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status_class",
            "in": "query",
            "schema": {
              "enum": [
                "2xx",
                "4xx",
                "5xx"
              ],
              "type": "string",
              "description": "Solo llamadas con estado `2xx`, `4xx` o `5xx`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Inicio del intervalo (ISO 8601), como máximo hace 30 días; por defecto = hace 30 días."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fin del intervalo (ISO 8601); por defecto = ahora."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Las llamadas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del registro."
                          },
                          "api_key_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Clave usada en la llamada."
                          },
                          "request_id": {
                            "type": "string",
                            "description": "ID de la solicitud (cabecera `X-Request-Id`)."
                          },
                          "method": {
                            "type": "string",
                            "description": "Método HTTP."
                          },
                          "path": {
                            "type": "string",
                            "description": "Ruta llamada, sin la query."
                          },
                          "status": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Estado HTTP de la respuesta."
                          },
                          "duration_ms": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Duración, en milisegundos."
                          },
                          "error_code": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Código del error, cuando la llamada falló."
                          },
                          "idempotency_key": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "`Idempotency-Key` enviada, si la hubo."
                          },
                          "ip": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "IP de origen."
                          },
                          "user_agent": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "User-Agent del cliente."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se hizo la llamada (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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 conexiones",
        "description": "Lista las conexiones de la organización (números de WhatsApp y, en las próximas fases, cuentas de Instagram y Messenger), de la más nueva a la más antigua, con los datos del canal. Una clave limitada a conexiones solo ve las suyas. Permiso: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending",
                "active",
                "needs_reconnect",
                "restricted",
                "disabled",
                "disconnected"
              ],
              "type": "string",
              "description": "Solo conexiones con este estado."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de conexiones.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la conexión (`con_…`).",
                            "examples": [
                              "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "channel": {
                            "enum": [
                              "whatsapp",
                              "instagram",
                              "messenger"
                            ],
                            "type": "string",
                            "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                          },
                          "status": {
                            "enum": [
                              "pending",
                              "active",
                              "needs_reconnect",
                              "restricted",
                              "disabled",
                              "disconnected"
                            ],
                            "type": "string",
                            "description": "Estado: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` o `disconnected`."
                          },
                          "status_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo del estado actual, cuando lo hay."
                          },
                          "label": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre que la organización dio a la conexión."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID en Meta (en WhatsApp, el `phone_number_id`)."
                          },
                          "external_label": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Etiqueta que viene de Meta, p. ej., el número formateado."
                          },
                          "mode": {
                            "anyOf": [
                              {
                                "enum": [
                                  "coex",
                                  "api_only"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                          },
                          "send_rate_mps": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                          },
                          "connected_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo la conexión quedó activa (ISO 8601, UTC)."
                          },
                          "last_webhook_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último webhook recibido (ISO 8601, UTC); se actualiza como máximo cada 30 s."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó la conexión (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio (ISO 8601, UTC)."
                          },
                          "whatsapp": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "phone_number_id": {
                                    "type": "string",
                                    "description": "ID del número en Meta."
                                  },
                                  "messaging_account_id": {
                                    "type": "string",
                                    "description": "Cuenta de WhatsApp Business (WABA) del número."
                                  },
                                  "mode": {
                                    "enum": [
                                      "coex",
                                      "api_only"
                                    ],
                                    "type": "string",
                                    "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                                  },
                                  "display_phone_number": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Número como lo muestra Meta."
                                  },
                                  "verified_name": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nombre visible aprobado."
                                  },
                                  "quality_rating": {
                                    "type": "string",
                                    "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                                  },
                                  "messaging_limit": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nivel de mensajes de Meta, p. ej., `TIER_2K`."
                                  },
                                  "throughput_level": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nivel de rendimiento: `STANDARD`, `HIGH` o `NOT_APPLICABLE`."
                                  },
                                  "send_rate_mps": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                                  },
                                  "can_send_message": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Si Meta permite enviar: `AVAILABLE`, `LIMITED` o `BLOCKED`."
                                  },
                                  "restriction": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "types": {
                                            "type": "array",
                                            "items": {
                                              "type": "string"
                                            },
                                            "description": "Tipos de restricción informados por Meta."
                                          },
                                          "until": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ],
                                            "description": "Hasta cuándo vale (ISO 8601), si Meta lo informó."
                                          },
                                          "remediation": {
                                            "anyOf": [
                                              {
                                                "type": "string"
                                              },
                                              {
                                                "type": "null"
                                              }
                                            ],
                                            "description": "Qué hacer para salir de la restricción."
                                          }
                                        },
                                        "required": [
                                          "types",
                                          "until",
                                          "remediation"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Restricción activa de la cuenta; `null` sin restricción."
                                  },
                                  "register_status": {
                                    "type": "string",
                                    "description": "Registro en la Cloud API: `not_needed`, `pending`, `registered` o `failed`."
                                  },
                                  "contacts_sync_status": {
                                    "type": "string",
                                    "description": "Sincronización de contactos de la coexistencia."
                                  },
                                  "history_sync_status": {
                                    "type": "string",
                                    "description": "Sincronización del historial de la coexistencia."
                                  },
                                  "history_sync_progress": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Progreso del historial, de 0 a 100."
                                  },
                                  "username": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nombre de usuario de 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": "Datos de WhatsApp; `null` en los otros canales."
                          },
                          "instagram": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "ig_user_id": {
                                    "type": "string",
                                    "description": "ID de la cuenta profesional de Instagram (`ig_user_id`)."
                                  },
                                  "username": {
                                    "type": "string",
                                    "description": "Nombre de usuario de la cuenta (@)."
                                  },
                                  "name": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Nombre visible de la cuenta."
                                  },
                                  "account_type": {
                                    "type": "string",
                                    "description": "Tipo de cuenta: `BUSINESS` o `MEDIA_CREATOR`. Las conexiones del inicio de sesión unificado informan `BUSINESS` hasta la pendencia 2-20."
                                  },
                                  "scopes": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Permisos concedidos por Meta."
                                  },
                                  "missing_scopes": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Permisos de Instagram no concedidos; lo que depende de ellos responde `403 instagram_scope_missing` hasta reconectar."
                                  },
                                  "token_expires_at": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Cuándo vence el token (ISO 8601, UTC). Siempre nulo en Instagram: el token no vence."
                                  },
                                  "token_refreshed_at": {
                                    "type": "string",
                                    "description": "Cuándo se emitió el token actual, al conectar o reconectar (ISO 8601, UTC)."
                                  },
                                  "followers_count": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Seguidores en la última lectura."
                                  },
                                  "publishing_quota": {
                                    "anyOf": [
                                      {
                                        "type": "object",
                                        "properties": {
                                          "quota_usage": {
                                            "type": "integer",
                                            "minimum": -9007199254740991,
                                            "maximum": 9007199254740991,
                                            "description": "Publicaciones hechas en la ventana de la cuota."
                                          },
                                          "quota_total": {
                                            "type": "integer",
                                            "minimum": -9007199254740991,
                                            "maximum": 9007199254740991,
                                            "description": "Publicaciones permitidas en la ventana."
                                          },
                                          "quota_duration_s": {
                                            "type": "integer",
                                            "minimum": -9007199254740991,
                                            "maximum": 9007199254740991,
                                            "description": "Duración de la ventana, en segundos."
                                          },
                                          "checked_at": {
                                            "type": "string",
                                            "description": "Cuándo se leyó la cuota (ISO 8601, UTC)."
                                          }
                                        },
                                        "required": [
                                          "quota_usage",
                                          "quota_total",
                                          "quota_duration_s",
                                          "checked_at"
                                        ]
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Cuota de publicación en el último chequeo de salud; `null` sin el permiso 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": "Datos de Instagram; `null` en los otros canales."
                          },
                          "messenger": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "page_id": {
                                    "type": "string",
                                    "description": "ID de la Página de Facebook."
                                  },
                                  "page_name": {
                                    "type": "string",
                                    "description": "Nombre de la Página."
                                  },
                                  "page_category": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Categoría de la Página."
                                  },
                                  "tasks": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Tareas que el usuario que conectó tiene en la Página (`MESSAGING`, `MANAGE`…)."
                                  },
                                  "scopes": {
                                    "type": "array",
                                    "items": {
                                      "type": "string"
                                    },
                                    "description": "Permisos concedidos por Meta."
                                  }
                                },
                                "required": [
                                  "page_id",
                                  "page_name",
                                  "page_category",
                                  "tasks",
                                  "scopes"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Datos de la Página de Facebook (Messenger); `null` en los otros canales."
                          }
                        },
                        "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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Obtener una conexión",
        "description": "Devuelve la conexión con estado, modo, velocidad de envío y, en WhatsApp, calidad, límite de mensajes, restricciones y el estado del registro y de la sincronización de la coexistencia. Permiso: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La conexión.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la conexión (`con_…`).",
                      "examples": [
                        "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "active",
                        "needs_reconnect",
                        "restricted",
                        "disabled",
                        "disconnected"
                      ],
                      "type": "string",
                      "description": "Estado: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` o `disconnected`."
                    },
                    "status_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del estado actual, cuando lo hay."
                    },
                    "label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre que la organización dio a la conexión."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID en Meta (en WhatsApp, el `phone_number_id`)."
                    },
                    "external_label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Etiqueta que viene de Meta, p. ej., el número formateado."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                    },
                    "send_rate_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                    },
                    "connected_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la conexión quedó activa (ISO 8601, UTC)."
                    },
                    "last_webhook_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último webhook recibido (ISO 8601, UTC); se actualiza como máximo cada 30 s."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la conexión (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (ISO 8601, UTC)."
                    },
                    "whatsapp": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "phone_number_id": {
                              "type": "string",
                              "description": "ID del número en Meta."
                            },
                            "messaging_account_id": {
                              "type": "string",
                              "description": "Cuenta de WhatsApp Business (WABA) del número."
                            },
                            "mode": {
                              "enum": [
                                "coex",
                                "api_only"
                              ],
                              "type": "string",
                              "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                            },
                            "display_phone_number": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Número como lo muestra Meta."
                            },
                            "verified_name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre visible aprobado."
                            },
                            "quality_rating": {
                              "type": "string",
                              "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                            },
                            "messaging_limit": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nivel de mensajes de Meta, p. ej., `TIER_2K`."
                            },
                            "throughput_level": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nivel de rendimiento: `STANDARD`, `HIGH` o `NOT_APPLICABLE`."
                            },
                            "send_rate_mps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                            },
                            "can_send_message": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Si Meta permite enviar: `AVAILABLE`, `LIMITED` o `BLOCKED`."
                            },
                            "restriction": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "types": {
                                      "type": "array",
                                      "items": {
                                        "type": "string"
                                      },
                                      "description": "Tipos de restricción informados por Meta."
                                    },
                                    "until": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Hasta cuándo vale (ISO 8601), si Meta lo informó."
                                    },
                                    "remediation": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Qué hacer para salir de la restricción."
                                    }
                                  },
                                  "required": [
                                    "types",
                                    "until",
                                    "remediation"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Restricción activa de la cuenta; `null` sin restricción."
                            },
                            "register_status": {
                              "type": "string",
                              "description": "Registro en la Cloud API: `not_needed`, `pending`, `registered` o `failed`."
                            },
                            "contacts_sync_status": {
                              "type": "string",
                              "description": "Sincronización de contactos de la coexistencia."
                            },
                            "history_sync_status": {
                              "type": "string",
                              "description": "Sincronización del historial de la coexistencia."
                            },
                            "history_sync_progress": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Progreso del historial, de 0 a 100."
                            },
                            "username": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre de usuario de 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": "Datos de WhatsApp; `null` en los otros canales."
                    },
                    "instagram": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ig_user_id": {
                              "type": "string",
                              "description": "ID de la cuenta profesional de Instagram (`ig_user_id`)."
                            },
                            "username": {
                              "type": "string",
                              "description": "Nombre de usuario de la cuenta (@)."
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre visible de la cuenta."
                            },
                            "account_type": {
                              "type": "string",
                              "description": "Tipo de cuenta: `BUSINESS` o `MEDIA_CREATOR`. Las conexiones del inicio de sesión unificado informan `BUSINESS` hasta la pendencia 2-20."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos concedidos por Meta."
                            },
                            "missing_scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos de Instagram no concedidos; lo que depende de ellos responde `403 instagram_scope_missing` hasta reconectar."
                            },
                            "token_expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el token (ISO 8601, UTC). Siempre nulo en Instagram: el token no vence."
                            },
                            "token_refreshed_at": {
                              "type": "string",
                              "description": "Cuándo se emitió el token actual, al conectar o reconectar (ISO 8601, UTC)."
                            },
                            "followers_count": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Seguidores en la última lectura."
                            },
                            "publishing_quota": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "quota_usage": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicaciones hechas en la ventana de la cuota."
                                    },
                                    "quota_total": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicaciones permitidas en la ventana."
                                    },
                                    "quota_duration_s": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Duración de la ventana, en segundos."
                                    },
                                    "checked_at": {
                                      "type": "string",
                                      "description": "Cuándo se leyó la cuota (ISO 8601, UTC)."
                                    }
                                  },
                                  "required": [
                                    "quota_usage",
                                    "quota_total",
                                    "quota_duration_s",
                                    "checked_at"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuota de publicación en el último chequeo de salud; `null` sin el permiso 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": "Datos de Instagram; `null` en los otros canales."
                    },
                    "messenger": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "page_id": {
                              "type": "string",
                              "description": "ID de la Página de Facebook."
                            },
                            "page_name": {
                              "type": "string",
                              "description": "Nombre de la Página."
                            },
                            "page_category": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Categoría de la Página."
                            },
                            "tasks": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Tareas que el usuario que conectó tiene en la Página (`MESSAGING`, `MANAGE`…)."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos concedidos por Meta."
                            }
                          },
                          "required": [
                            "page_id",
                            "page_name",
                            "page_category",
                            "tasks",
                            "scopes"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Datos de la Página de Facebook (Messenger); `null` en los otros canales."
                    }
                  },
                  "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": "Renombrar una conexión",
        "description": "Cambia el nombre que la organización da a la conexión (no cambia nada en Meta). Permiso: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Nombre que la organización dio a la conexión."
                  }
                },
                "required": [
                  "label"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La conexión actualizada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la conexión (`con_…`).",
                      "examples": [
                        "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "active",
                        "needs_reconnect",
                        "restricted",
                        "disabled",
                        "disconnected"
                      ],
                      "type": "string",
                      "description": "Estado: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` o `disconnected`."
                    },
                    "status_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del estado actual, cuando lo hay."
                    },
                    "label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre que la organización dio a la conexión."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID en Meta (en WhatsApp, el `phone_number_id`)."
                    },
                    "external_label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Etiqueta que viene de Meta, p. ej., el número formateado."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                    },
                    "send_rate_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                    },
                    "connected_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la conexión quedó activa (ISO 8601, UTC)."
                    },
                    "last_webhook_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último webhook recibido (ISO 8601, UTC); se actualiza como máximo cada 30 s."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la conexión (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (ISO 8601, UTC)."
                    },
                    "whatsapp": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "phone_number_id": {
                              "type": "string",
                              "description": "ID del número en Meta."
                            },
                            "messaging_account_id": {
                              "type": "string",
                              "description": "Cuenta de WhatsApp Business (WABA) del número."
                            },
                            "mode": {
                              "enum": [
                                "coex",
                                "api_only"
                              ],
                              "type": "string",
                              "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                            },
                            "display_phone_number": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Número como lo muestra Meta."
                            },
                            "verified_name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre visible aprobado."
                            },
                            "quality_rating": {
                              "type": "string",
                              "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                            },
                            "messaging_limit": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nivel de mensajes de Meta, p. ej., `TIER_2K`."
                            },
                            "throughput_level": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nivel de rendimiento: `STANDARD`, `HIGH` o `NOT_APPLICABLE`."
                            },
                            "send_rate_mps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                            },
                            "can_send_message": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Si Meta permite enviar: `AVAILABLE`, `LIMITED` o `BLOCKED`."
                            },
                            "restriction": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "types": {
                                      "type": "array",
                                      "items": {
                                        "type": "string"
                                      },
                                      "description": "Tipos de restricción informados por Meta."
                                    },
                                    "until": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Hasta cuándo vale (ISO 8601), si Meta lo informó."
                                    },
                                    "remediation": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Qué hacer para salir de la restricción."
                                    }
                                  },
                                  "required": [
                                    "types",
                                    "until",
                                    "remediation"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Restricción activa de la cuenta; `null` sin restricción."
                            },
                            "register_status": {
                              "type": "string",
                              "description": "Registro en la Cloud API: `not_needed`, `pending`, `registered` o `failed`."
                            },
                            "contacts_sync_status": {
                              "type": "string",
                              "description": "Sincronización de contactos de la coexistencia."
                            },
                            "history_sync_status": {
                              "type": "string",
                              "description": "Sincronización del historial de la coexistencia."
                            },
                            "history_sync_progress": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Progreso del historial, de 0 a 100."
                            },
                            "username": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre de usuario de 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": "Datos de WhatsApp; `null` en los otros canales."
                    },
                    "instagram": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ig_user_id": {
                              "type": "string",
                              "description": "ID de la cuenta profesional de Instagram (`ig_user_id`)."
                            },
                            "username": {
                              "type": "string",
                              "description": "Nombre de usuario de la cuenta (@)."
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre visible de la cuenta."
                            },
                            "account_type": {
                              "type": "string",
                              "description": "Tipo de cuenta: `BUSINESS` o `MEDIA_CREATOR`. Las conexiones del inicio de sesión unificado informan `BUSINESS` hasta la pendencia 2-20."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos concedidos por Meta."
                            },
                            "missing_scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos de Instagram no concedidos; lo que depende de ellos responde `403 instagram_scope_missing` hasta reconectar."
                            },
                            "token_expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el token (ISO 8601, UTC). Siempre nulo en Instagram: el token no vence."
                            },
                            "token_refreshed_at": {
                              "type": "string",
                              "description": "Cuándo se emitió el token actual, al conectar o reconectar (ISO 8601, UTC)."
                            },
                            "followers_count": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Seguidores en la última lectura."
                            },
                            "publishing_quota": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "quota_usage": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicaciones hechas en la ventana de la cuota."
                                    },
                                    "quota_total": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicaciones permitidas en la ventana."
                                    },
                                    "quota_duration_s": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Duración de la ventana, en segundos."
                                    },
                                    "checked_at": {
                                      "type": "string",
                                      "description": "Cuándo se leyó la cuota (ISO 8601, UTC)."
                                    }
                                  },
                                  "required": [
                                    "quota_usage",
                                    "quota_total",
                                    "quota_duration_s",
                                    "checked_at"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuota de publicación en el último chequeo de salud; `null` sin el permiso 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": "Datos de Instagram; `null` en los otros canales."
                    },
                    "messenger": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "page_id": {
                              "type": "string",
                              "description": "ID de la Página de Facebook."
                            },
                            "page_name": {
                              "type": "string",
                              "description": "Nombre de la Página."
                            },
                            "page_category": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Categoría de la Página."
                            },
                            "tasks": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Tareas que el usuario que conectó tiene en la Página (`MESSAGING`, `MANAGE`…)."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos concedidos por Meta."
                            }
                          },
                          "required": [
                            "page_id",
                            "page_name",
                            "page_category",
                            "tasks",
                            "scopes"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Datos de la Página de Facebook (Messenger); `null` en los otros canales."
                    }
                  },
                  "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 la conexión: la credencial se revoca, los webhooks dejan de llegar y el número sale de la facturación. En el modo solo API, `deregister: true` también quita el número de la Cloud API. Los fallos del lado de Meta no impiden la desconexión y vuelven en `warnings`. Permiso: `admin`. Requiere una clave de la organización.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "deregister": {
                    "type": "boolean",
                    "description": "Solo API: también quita el número de la Cloud API."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La conexión desconectada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la conexión (`con_…`).",
                      "examples": [
                        "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "active",
                        "needs_reconnect",
                        "restricted",
                        "disabled",
                        "disconnected"
                      ],
                      "type": "string",
                      "description": "Estado: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` o `disconnected`."
                    },
                    "status_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del estado actual, cuando lo hay."
                    },
                    "label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre que la organización dio a la conexión."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID en Meta (en WhatsApp, el `phone_number_id`)."
                    },
                    "external_label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Etiqueta que viene de Meta, p. ej., el número formateado."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                    },
                    "send_rate_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                    },
                    "connected_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la conexión quedó activa (ISO 8601, UTC)."
                    },
                    "last_webhook_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último webhook recibido (ISO 8601, UTC); se actualiza como máximo cada 30 s."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la conexión (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (ISO 8601, UTC)."
                    },
                    "whatsapp": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "phone_number_id": {
                              "type": "string",
                              "description": "ID del número en Meta."
                            },
                            "messaging_account_id": {
                              "type": "string",
                              "description": "Cuenta de WhatsApp Business (WABA) del número."
                            },
                            "mode": {
                              "enum": [
                                "coex",
                                "api_only"
                              ],
                              "type": "string",
                              "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                            },
                            "display_phone_number": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Número como lo muestra Meta."
                            },
                            "verified_name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre visible aprobado."
                            },
                            "quality_rating": {
                              "type": "string",
                              "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                            },
                            "messaging_limit": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nivel de mensajes de Meta, p. ej., `TIER_2K`."
                            },
                            "throughput_level": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nivel de rendimiento: `STANDARD`, `HIGH` o `NOT_APPLICABLE`."
                            },
                            "send_rate_mps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                            },
                            "can_send_message": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Si Meta permite enviar: `AVAILABLE`, `LIMITED` o `BLOCKED`."
                            },
                            "restriction": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "types": {
                                      "type": "array",
                                      "items": {
                                        "type": "string"
                                      },
                                      "description": "Tipos de restricción informados por Meta."
                                    },
                                    "until": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Hasta cuándo vale (ISO 8601), si Meta lo informó."
                                    },
                                    "remediation": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Qué hacer para salir de la restricción."
                                    }
                                  },
                                  "required": [
                                    "types",
                                    "until",
                                    "remediation"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Restricción activa de la cuenta; `null` sin restricción."
                            },
                            "register_status": {
                              "type": "string",
                              "description": "Registro en la Cloud API: `not_needed`, `pending`, `registered` o `failed`."
                            },
                            "contacts_sync_status": {
                              "type": "string",
                              "description": "Sincronización de contactos de la coexistencia."
                            },
                            "history_sync_status": {
                              "type": "string",
                              "description": "Sincronización del historial de la coexistencia."
                            },
                            "history_sync_progress": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Progreso del historial, de 0 a 100."
                            },
                            "username": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre de usuario de 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": "Datos de WhatsApp; `null` en los otros canales."
                    },
                    "instagram": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ig_user_id": {
                              "type": "string",
                              "description": "ID de la cuenta profesional de Instagram (`ig_user_id`)."
                            },
                            "username": {
                              "type": "string",
                              "description": "Nombre de usuario de la cuenta (@)."
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre visible de la cuenta."
                            },
                            "account_type": {
                              "type": "string",
                              "description": "Tipo de cuenta: `BUSINESS` o `MEDIA_CREATOR`. Las conexiones del inicio de sesión unificado informan `BUSINESS` hasta la pendencia 2-20."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos concedidos por Meta."
                            },
                            "missing_scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos de Instagram no concedidos; lo que depende de ellos responde `403 instagram_scope_missing` hasta reconectar."
                            },
                            "token_expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el token (ISO 8601, UTC). Siempre nulo en Instagram: el token no vence."
                            },
                            "token_refreshed_at": {
                              "type": "string",
                              "description": "Cuándo se emitió el token actual, al conectar o reconectar (ISO 8601, UTC)."
                            },
                            "followers_count": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Seguidores en la última lectura."
                            },
                            "publishing_quota": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "quota_usage": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicaciones hechas en la ventana de la cuota."
                                    },
                                    "quota_total": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicaciones permitidas en la ventana."
                                    },
                                    "quota_duration_s": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Duración de la ventana, en segundos."
                                    },
                                    "checked_at": {
                                      "type": "string",
                                      "description": "Cuándo se leyó la cuota (ISO 8601, UTC)."
                                    }
                                  },
                                  "required": [
                                    "quota_usage",
                                    "quota_total",
                                    "quota_duration_s",
                                    "checked_at"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuota de publicación en el último chequeo de salud; `null` sin el permiso 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": "Datos de Instagram; `null` en los otros canales."
                    },
                    "messenger": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "page_id": {
                              "type": "string",
                              "description": "ID de la Página de Facebook."
                            },
                            "page_name": {
                              "type": "string",
                              "description": "Nombre de la Página."
                            },
                            "page_category": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Categoría de la Página."
                            },
                            "tasks": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Tareas que el usuario que conectó tiene en la Página (`MESSAGING`, `MANAGE`…)."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos concedidos por Meta."
                            }
                          },
                          "required": [
                            "page_id",
                            "page_name",
                            "page_category",
                            "tasks",
                            "scopes"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Datos de la Página de Facebook (Messenger); `null` en los otros canales."
                    },
                    "warnings": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Fallos del lado de Meta que no impidieron la desconexión."
                    }
                  },
                  "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 las claves de una conexión",
        "description": "Lista las claves de API ligadas a esta conexión (las claves de organización no aparecen). Permiso: `admin`. Requiere clave de la organización.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador de la conexión."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Las claves de la conexión.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Identificador de la clave."
                          },
                          "name": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre de la clave (hasta 32 caracteres)."
                          },
                          "start": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Inicio visible de la clave, para identificarla."
                          },
                          "permissions": {
                            "type": "array",
                            "items": {
                              "enum": [
                                "send",
                                "read",
                                "templates",
                                "commerce",
                                "admin"
                              ],
                              "type": "string"
                            },
                            "description": "Permisos de la clave (`admin` implica las demás)."
                          },
                          "enabled": {
                            "type": "boolean",
                            "description": "Si la clave está activa."
                          },
                          "expires_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo expira la clave; `null` = no expira."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó la clave."
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "start",
                          "permissions",
                          "enabled",
                          "expires_at",
                          "created_at"
                        ]
                      },
                      "description": "Las claves de la conexión."
                    }
                  },
                  "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": "Crear una clave de conexión",
        "description": "Crea una clave ligada a esta conexión (prefijo `mjc_`): envía sin `connection_id` y no accede a rutas de organización. El secreto (`key`) aparece solo en esta respuesta. Permiso: `admin`. Requiere clave de la organización.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador de la conexión."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 32,
                    "description": "Nombre de la clave (hasta 32 caracteres)."
                  },
                  "permissions": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "enum": [
                        "send",
                        "read",
                        "templates",
                        "commerce",
                        "admin"
                      ],
                      "type": "string"
                    },
                    "description": "Permisos de la clave (`admin` implica las demás)."
                  },
                  "expires_in_days": {
                    "anyOf": [
                      {
                        "type": "null"
                      },
                      {
                        "const": 30
                      },
                      {
                        "const": 90
                      },
                      {
                        "const": 180
                      },
                      {
                        "const": 365
                      }
                    ],
                    "default": null,
                    "description": "Vigencia en días (`null` = no expira). Valores aceptados: 30, 90, 180 o 365."
                  },
                  "rate_per_minute": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 6000,
                    "default": 600,
                    "description": "Límite de solicitudes por minuto de la clave."
                  }
                },
                "required": [
                  "name",
                  "permissions"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "La clave creada, con su secreto.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Identificador de la clave."
                    },
                    "name": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre de la clave (hasta 32 caracteres)."
                    },
                    "start": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio visible de la clave, para identificarla."
                    },
                    "permissions": {
                      "type": "array",
                      "items": {
                        "enum": [
                          "send",
                          "read",
                          "templates",
                          "commerce",
                          "admin"
                        ],
                        "type": "string"
                      },
                      "description": "Permisos de la clave (`admin` implica las demás)."
                    },
                    "enabled": {
                      "type": "boolean",
                      "description": "Si la clave está activa."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo expira la clave; `null` = no expira."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la clave."
                    },
                    "key": {
                      "type": "string",
                      "description": "El secreto de la clave. Aparece solo al crearla: guárdelo."
                    }
                  },
                  "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": "Eliminar una clave de API",
        "description": "Elimina la clave de API (de organización o de conexión) y deja de funcionar al instante. Permiso: `admin`. Requiere clave de la organización; una clave limitada a conexiones solo alcanza claves dentro de ellas.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador de la clave."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La clave eliminada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Identificador de la clave."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `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": "Rotar una clave de API",
        "description": "Crea una clave nueva con el mismo nombre, permisos, alcance y límite, y mantiene la anterior durante `grace` (`24h`, por defecto, o `now`, vence al instante). El secreto nuevo (`key`) aparece solo en esta respuesta. Permiso: `admin`. Requiere clave de la organización.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Identificador de la clave."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "grace": {
                    "enum": [
                      "now",
                      "24h"
                    ],
                    "type": "string",
                    "default": "24h",
                    "description": "Gracia de la clave anterior: `24h` (por defecto) o `now`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "La clave nueva, con su secreto.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Identificador de la clave."
                    },
                    "name": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre de la clave (hasta 32 caracteres)."
                    },
                    "start": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio visible de la clave, para identificarla."
                    },
                    "permissions": {
                      "type": "array",
                      "items": {
                        "enum": [
                          "send",
                          "read",
                          "templates",
                          "commerce",
                          "admin"
                        ],
                        "type": "string"
                      },
                      "description": "Permisos de la clave (`admin` implica las demás)."
                    },
                    "enabled": {
                      "type": "boolean",
                      "description": "Si la clave está activa."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo expira la clave; `null` = no expira."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la clave."
                    },
                    "key": {
                      "type": "string",
                      "description": "El secreto de la clave. Aparece solo al crearla: guárdelo."
                    },
                    "previous_key_expires_at": {
                      "type": "string",
                      "description": "Cuándo deja de valer la clave anterior (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": "Actualizar la salud",
        "description": "Lee ahora en Meta la calidad, el límite de mensajes, la velocidad y el `can_send_message` del número (Messajo ya lo hace cada 15 minutos). Un token inválido marca la conexión como `needs_reconnect`. Permiso: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La conexión con la lectura nueva.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la conexión (`con_…`).",
                      "examples": [
                        "con_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "active",
                        "needs_reconnect",
                        "restricted",
                        "disabled",
                        "disconnected"
                      ],
                      "type": "string",
                      "description": "Estado: `pending`, `active`, `restricted`, `needs_reconnect`, `banned` o `disconnected`."
                    },
                    "status_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del estado actual, cuando lo hay."
                    },
                    "label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre que la organización dio a la conexión."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID en Meta (en WhatsApp, el `phone_number_id`)."
                    },
                    "external_label": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Etiqueta que viene de Meta, p. ej., el número formateado."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                    },
                    "send_rate_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                    },
                    "connected_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo la conexión quedó activa (ISO 8601, UTC)."
                    },
                    "last_webhook_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último webhook recibido (ISO 8601, UTC); se actualiza como máximo cada 30 s."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la conexión (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (ISO 8601, UTC)."
                    },
                    "whatsapp": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "phone_number_id": {
                              "type": "string",
                              "description": "ID del número en Meta."
                            },
                            "messaging_account_id": {
                              "type": "string",
                              "description": "Cuenta de WhatsApp Business (WABA) del número."
                            },
                            "mode": {
                              "enum": [
                                "coex",
                                "api_only"
                              ],
                              "type": "string",
                              "description": "Modo en WhatsApp: `coex` (coexistencia con la app) o `api_only`."
                            },
                            "display_phone_number": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Número como lo muestra Meta."
                            },
                            "verified_name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre visible aprobado."
                            },
                            "quality_rating": {
                              "type": "string",
                              "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                            },
                            "messaging_limit": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nivel de mensajes de Meta, p. ej., `TIER_2K`."
                            },
                            "throughput_level": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nivel de rendimiento: `STANDARD`, `HIGH` o `NOT_APPLICABLE`."
                            },
                            "send_rate_mps": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Mensajes por segundo que Messajo deja salir por esta conexión."
                            },
                            "can_send_message": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Si Meta permite enviar: `AVAILABLE`, `LIMITED` o `BLOCKED`."
                            },
                            "restriction": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "types": {
                                      "type": "array",
                                      "items": {
                                        "type": "string"
                                      },
                                      "description": "Tipos de restricción informados por Meta."
                                    },
                                    "until": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Hasta cuándo vale (ISO 8601), si Meta lo informó."
                                    },
                                    "remediation": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        },
                                        {
                                          "type": "null"
                                        }
                                      ],
                                      "description": "Qué hacer para salir de la restricción."
                                    }
                                  },
                                  "required": [
                                    "types",
                                    "until",
                                    "remediation"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Restricción activa de la cuenta; `null` sin restricción."
                            },
                            "register_status": {
                              "type": "string",
                              "description": "Registro en la Cloud API: `not_needed`, `pending`, `registered` o `failed`."
                            },
                            "contacts_sync_status": {
                              "type": "string",
                              "description": "Sincronización de contactos de la coexistencia."
                            },
                            "history_sync_status": {
                              "type": "string",
                              "description": "Sincronización del historial de la coexistencia."
                            },
                            "history_sync_progress": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Progreso del historial, de 0 a 100."
                            },
                            "username": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre de usuario de 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": "Datos de WhatsApp; `null` en los otros canales."
                    },
                    "instagram": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "ig_user_id": {
                              "type": "string",
                              "description": "ID de la cuenta profesional de Instagram (`ig_user_id`)."
                            },
                            "username": {
                              "type": "string",
                              "description": "Nombre de usuario de la cuenta (@)."
                            },
                            "name": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Nombre visible de la cuenta."
                            },
                            "account_type": {
                              "type": "string",
                              "description": "Tipo de cuenta: `BUSINESS` o `MEDIA_CREATOR`. Las conexiones del inicio de sesión unificado informan `BUSINESS` hasta la pendencia 2-20."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos concedidos por Meta."
                            },
                            "missing_scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos de Instagram no concedidos; lo que depende de ellos responde `403 instagram_scope_missing` hasta reconectar."
                            },
                            "token_expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el token (ISO 8601, UTC). Siempre nulo en Instagram: el token no vence."
                            },
                            "token_refreshed_at": {
                              "type": "string",
                              "description": "Cuándo se emitió el token actual, al conectar o reconectar (ISO 8601, UTC)."
                            },
                            "followers_count": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Seguidores en la última lectura."
                            },
                            "publishing_quota": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "quota_usage": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicaciones hechas en la ventana de la cuota."
                                    },
                                    "quota_total": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Publicaciones permitidas en la ventana."
                                    },
                                    "quota_duration_s": {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Duración de la ventana, en segundos."
                                    },
                                    "checked_at": {
                                      "type": "string",
                                      "description": "Cuándo se leyó la cuota (ISO 8601, UTC)."
                                    }
                                  },
                                  "required": [
                                    "quota_usage",
                                    "quota_total",
                                    "quota_duration_s",
                                    "checked_at"
                                  ]
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuota de publicación en el último chequeo de salud; `null` sin el permiso 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": "Datos de Instagram; `null` en los otros canales."
                    },
                    "messenger": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "page_id": {
                              "type": "string",
                              "description": "ID de la Página de Facebook."
                            },
                            "page_name": {
                              "type": "string",
                              "description": "Nombre de la Página."
                            },
                            "page_category": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Categoría de la Página."
                            },
                            "tasks": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Tareas que el usuario que conectó tiene en la Página (`MESSAGING`, `MANAGE`…)."
                            },
                            "scopes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Permisos concedidos por Meta."
                            }
                          },
                          "required": [
                            "page_id",
                            "page_name",
                            "page_category",
                            "tasks",
                            "scopes"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Datos de la Página de Facebook (Messenger); `null` en los otros canales."
                    }
                  },
                  "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": "Obtener el perfil comercial",
        "description": "Devuelve el perfil comercial del número en Meta (acerca de, dirección, descripción, correo, sitios, sector y foto). Permiso: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El perfil comercial.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "about": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto \"acerca de\" del perfil."
                    },
                    "address": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dirección."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción de la empresa."
                    },
                    "email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Correo de contacto."
                    },
                    "websites": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Hasta 2 sitios."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Sector de la empresa, p. ej., `RETAIL`."
                    },
                    "profile_picture_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enlace de la foto del perfil en 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 el perfil comercial",
        "description": "Cambia los campos enviados del perfil comercial. La foto viene de un medio subido antes con `POST /media`. En la coexistencia Meta no permite editar por la API: la respuesta es `422 coex_not_supported` (edítelo en la app del celular). Permiso: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "about": {
                    "type": "string",
                    "description": "Texto \"acerca de\" del perfil."
                  },
                  "address": {
                    "type": "string",
                    "description": "Dirección."
                  },
                  "description": {
                    "type": "string",
                    "description": "Descripción de la empresa."
                  },
                  "email": {
                    "type": "string",
                    "description": "Correo de contacto."
                  },
                  "websites": {
                    "type": "array",
                    "maxItems": 2,
                    "items": {
                      "type": "string"
                    },
                    "description": "Hasta 2 sitios."
                  },
                  "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": "Sector de la empresa, p. ej., `RETAIL`."
                  },
                  "profile_picture_media_id": {
                    "type": "string",
                    "description": "Medio (`med_…`) subido con `POST /media` para ser la foto."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El perfil comercial actualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "about": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto \"acerca de\" del perfil."
                    },
                    "address": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Dirección."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción de la empresa."
                    },
                    "email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Correo de contacto."
                    },
                    "websites": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Hasta 2 sitios."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Sector de la empresa, p. ej., `RETAIL`."
                    },
                    "profile_picture_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enlace de la foto del perfil en 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 nuevo nombre visible",
        "description": "Pide a Meta un nombre visible nuevo; pasa por revisión y el estado sale en `new_name_status`. En la coexistencia: `422 coex_not_supported`. Permiso: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Nombre visible pedido."
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El estado del pedido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "new_name_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado de la revisión del nombre nuevo en 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": "Obtener el nombre de usuario",
        "description": "Devuelve el nombre de usuario de WhatsApp del número y su estado en Meta. Permiso: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El nombre de usuario y el estado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "username": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre de usuario; `null` cuando no hay."
                    },
                    "status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado del nombre de usuario en 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 el nombre de usuario",
        "description": "Define o cambia el nombre de usuario del número (3 a 35 caracteres: letras, números, `.` y `_`). En la coexistencia: `422 coex_not_supported`. Permiso: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": {
                    "type": "string",
                    "description": "Nombre de usuario; `null` cuando no hay."
                  }
                },
                "required": [
                  "username"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El nombre de usuario y el estado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "username": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre de usuario; `null` cuando no hay."
                    },
                    "status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado del nombre de usuario en 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": "Quitar el nombre de usuario",
        "description": "Quita el nombre de usuario del número. En la coexistencia: `422 coex_not_supported`. Permiso: `admin`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El nombre de usuario (vacío) y el estado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "username": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre de usuario; `null` cuando no hay."
                    },
                    "status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado del nombre de usuario en 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": "Sugerencias de nombre de usuario",
        "description": "Nombres de usuario libres que Meta sugiere para el número. Permiso: `read`.",
        "tags": [
          "connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Las sugerencias.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "suggestions": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Nombres de usuario 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 mensaje",
        "description": "Envía un mensaje por una conexión. El cuerpo cambia según el canal (ver la unión abajo). WhatsApp: texto, multimedia, plantilla, interactivo, reacción, ubicación, contactos y sticker. Instagram y Messenger: `text` (con `quick_replies`), `image`, `images` (2 a 10, solo Instagram), `video`, `audio`, `document`, `like` (solo Instagram), `reaction`, `share` (post, solo Instagram), `buttons` y `cards`. Un tipo que el canal no tiene: `422 type_not_supported_by_channel`. Fuera de la ventana de 24 h: WhatsApp solo plantilla; Instagram y Messenger aceptan `tag: \"human_agent\"` hasta 7 días después del último mensaje del contacto, **solo para respuestas de una persona** (política de Meta; nunca en automatización), y después `422 human_agent_window_closed`. Sin la etiqueta: `422 outside_service_window`. Cada conexión tiene un límite de mensajes por segundo; por encima la respuesta es `429 connection_rate_limited` con `retry_after_ms`. Usa `Idempotency-Key` para repetir sin duplicar: si Meta no respondió si aceptó (`502 meta_unknown_outcome`), Messajo no reenvía solo. Permiso: `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": "Mensaje a enviar, en el formato del `type` elegido y del canal de la conexión."
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El mensaje guardado y aceptado por Meta.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del mensaje en Messajo (`msg_…`).",
                      "examples": [
                        "msg_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del mensaje en Meta (`wamid`)."
                    },
                    "status": {
                      "const": "queued",
                      "description": "Estado del mensaje; empieza en `queued` y cambia con los webhooks."
                    },
                    "meta_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Respuesta de Meta: `accepted`, `held_for_quality_assessment`, `paused` o `null`."
                    },
                    "conversation_id": {
                      "type": "string",
                      "description": "Conversación del mensaje."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contacto destinatario."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se guardó el mensaje (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 mensajes",
        "description": "Lista los mensajes de la organización con filtros. El intervalo `since`…`until` queda siempre dentro de la retención: un pedido mayor se recorta, sin error. Permiso: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "Cursor opaco de la página siguiente: el `next_cursor` de la respuesta anterior, con los mismos filtros. Alterado o de otra ruta → `400 invalid_cursor`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "order",
            "in": "query",
            "schema": {
              "enum": [
                "desc",
                "asc"
              ],
              "type": "string",
              "default": "desc",
              "description": "Orden: `desc` (por defecto, el más nuevo primero) o `asc`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "enum": [
                "inbound",
                "outbound"
              ],
              "type": "string",
              "description": "Dirección: `inbound` (recibido) u `outbound` (enviado)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Tipo del contenido, p. ej. `text`, `image`, `template`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Inicio del intervalo (ISO 8601). Por defecto y como límite: ahora menos la retención de la organización."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fin del intervalo (ISO 8601). Por defecto: ahora."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "contact_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del contacto."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "conversation_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conversación."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "received",
                "queued",
                "sent",
                "delivered",
                "read",
                "played",
                "failed",
                "deleted"
              ],
              "type": "string",
              "description": "Estado del mensaje."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "enum": [
                "customer",
                "api",
                "business_app",
                "history",
                "campaign"
              ],
              "type": "string",
              "description": "Origen: `customer`, `api`, `business_app`, `history` o `campaign`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "campaign_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Solo mensajes de esta campaña."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de mensajes.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del mensaje en Messajo (`msg_…`).",
                            "examples": [
                              "msg_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del mensaje en Meta; `null` antes de la aceptación."
                          },
                          "direction": {
                            "enum": [
                              "inbound",
                              "outbound"
                            ],
                            "type": "string",
                            "description": "Dirección: `inbound` (recibido) u `outbound` (enviado)."
                          },
                          "source": {
                            "enum": [
                              "customer",
                              "api",
                              "business_app",
                              "history",
                              "campaign"
                            ],
                            "type": "string",
                            "description": "Origen: `customer`, `api`, `business_app`, `history` o `campaign`."
                          },
                          "timestamp": {
                            "type": "string",
                            "description": "Cuándo ocurrió el mensaje (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": "Contenido normalizado (el mismo de los 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: respuesta, reenvío, anuncio de origen; `null` = sin contexto."
                          },
                          "conversation_id": {
                            "type": "string",
                            "description": "ID de la conversación."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del contacto."
                          },
                          "status": {
                            "enum": [
                              "received",
                              "queued",
                              "sent",
                              "delivered",
                              "read",
                              "played",
                              "failed",
                              "deleted"
                            ],
                            "type": "string",
                            "description": "Estado del mensaje."
                          },
                          "sent_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Enviado (ISO 8601, UTC)."
                          },
                          "delivered_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Entregado (ISO 8601, UTC)."
                          },
                          "read_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Leído (ISO 8601, UTC)."
                          },
                          "failed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Falló (ISO 8601, UTC)."
                          },
                          "edited_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Editado (ISO 8601, UTC)."
                          },
                          "revoked_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Borrado por el remitente (ISO 8601, UTC)."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Error del envío, en el formato de Meta; `null` = sin error."
                          },
                          "campaign": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "description": "Solo mensajes de esta campaña."
                                  },
                                  "recipient_id": {
                                    "type": "string",
                                    "description": "ID del destinatario de la campaña."
                                  }
                                },
                                "required": [
                                  "id",
                                  "recipient_id"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Campaña que envió el mensaje; `null` fuera de campaña."
                          }
                        },
                        "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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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 leído",
        "description": "Marca un mensaje recibido como leído. Con `typing: true` también muestra \"escribiendo…\" al contacto; en WhatsApp el \"escribiendo\" siempre marca como leído. Permiso: `send`.",
        "tags": [
          "messages"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Mensaje recibido (`msg_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "typing": {
                    "type": "boolean",
                    "default": false,
                    "description": "También mostrar \"escribiendo…\"."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Confirmación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Mensaje recibido (`msg_…`)."
                    },
                    "read": {
                      "const": true,
                      "description": "Siempre `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 plantillas",
        "description": "Lista las plantillas de las cuentas de WhatsApp de la organización, con filtros. Una clave limitada a conexiones debe informar `connection_id`. Permiso: `read`.",
        "tags": [
          "templates"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Conexión cuya cuenta de WhatsApp se usa. Opcional con una clave de conexión (usa la conexión de la clave)."
            },
            "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": "Estado en Meta, p. ej., `APPROVED`, `PENDING`, `REJECTED`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "enum": [
                "MARKETING",
                "UTILITY",
                "AUTHENTICATION"
              ],
              "type": "string",
              "description": "Categoría: `MARKETING`, `UTILITY` o `AUTHENTICATION`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "language",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Idioma, p. ej., `es`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "name",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Nombre (minúsculas, números y `_`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de plantillas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la plantilla en Messajo (`tpl_…`).",
                            "examples": [
                              "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "messaging_account_id": {
                            "type": "string",
                            "description": "Cuenta de WhatsApp Business (WABA) de la plantilla."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID de la plantilla en Meta."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nombre (minúsculas, números y `_`)."
                          },
                          "language": {
                            "type": "string",
                            "description": "Idioma, p. ej., `es`."
                          },
                          "category": {
                            "enum": [
                              "MARKETING",
                              "UTILITY",
                              "AUTHENTICATION"
                            ],
                            "type": "string",
                            "description": "Categoría: `MARKETING`, `UTILITY` o `AUTHENTICATION`."
                          },
                          "previous_category": {
                            "anyOf": [
                              {
                                "enum": [
                                  "MARKETING",
                                  "UTILITY",
                                  "AUTHENTICATION"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Categoría anterior, cuando Meta la reclasificó."
                          },
                          "status": {
                            "enum": [
                              "APPROVED",
                              "PENDING",
                              "REJECTED",
                              "PAUSED",
                              "DISABLED",
                              "IN_APPEAL",
                              "PENDING_DELETION",
                              "DELETED",
                              "ARCHIVED",
                              "LIMIT_EXCEEDED",
                              "LOCKED",
                              "FLAGGED",
                              "REINSTATED"
                            ],
                            "type": "string",
                            "description": "Estado en Meta, p. ej., `APPROVED`, `PENDING`, `REJECTED`."
                          },
                          "rejected_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo del rechazo, cuando lo hay."
                          },
                          "quality_score": {
                            "enum": [
                              "GREEN",
                              "YELLOW",
                              "RED",
                              "UNKNOWN"
                            ],
                            "type": "string",
                            "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                          },
                          "parameter_format": {
                            "enum": [
                              "POSITIONAL",
                              "NAMED"
                            ],
                            "type": "string",
                            "description": "Formato de las variables: `POSITIONAL` o `NAMED`."
                          },
                          "components": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            "description": "Componentes en el formato de Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                          },
                          "last_synced_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última lectura en Meta (ISO 8601, UTC)."
                          },
                          "status_updated_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último cambio de estado (ISO 8601, UTC)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó en Messajo (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Crear plantilla",
        "description": "Crea la plantilla en la cuenta de WhatsApp de la conexión y la envía a revisión de Meta; el estado cambia con el evento `template.status`. Permiso: `templates`.",
        "tags": [
          "templates"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexión cuya cuenta de WhatsApp se usa. Opcional con una clave de conexión (usa la conexión de la clave)."
                  },
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z0-9_]{1,512}$",
                    "description": "Nombre (minúsculas, números y `_`)."
                  },
                  "language": {
                    "type": "string",
                    "pattern": "^[a-z]{2,3}(_[A-Z]{2})?$",
                    "description": "Idioma, p. ej., `es`."
                  },
                  "category": {
                    "enum": [
                      "MARKETING",
                      "UTILITY",
                      "AUTHENTICATION"
                    ],
                    "type": "string",
                    "description": "Categoría: `MARKETING`, `UTILITY` o `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 en el formato de Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                  },
                  "parameter_format": {
                    "enum": [
                      "POSITIONAL",
                      "NAMED"
                    ],
                    "type": "string",
                    "description": "Formato de las variables: `POSITIONAL` o `NAMED`."
                  }
                },
                "required": [
                  "name",
                  "language",
                  "category",
                  "components"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "La plantilla creada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la plantilla en Messajo (`tpl_…`).",
                      "examples": [
                        "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Cuenta de WhatsApp Business (WABA) de la plantilla."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la plantilla en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre (minúsculas, números y `_`)."
                    },
                    "language": {
                      "type": "string",
                      "description": "Idioma, p. ej., `es`."
                    },
                    "category": {
                      "enum": [
                        "MARKETING",
                        "UTILITY",
                        "AUTHENTICATION"
                      ],
                      "type": "string",
                      "description": "Categoría: `MARKETING`, `UTILITY` o `AUTHENTICATION`."
                    },
                    "previous_category": {
                      "anyOf": [
                        {
                          "enum": [
                            "MARKETING",
                            "UTILITY",
                            "AUTHENTICATION"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Categoría anterior, cuando Meta la reclasificó."
                    },
                    "status": {
                      "enum": [
                        "APPROVED",
                        "PENDING",
                        "REJECTED",
                        "PAUSED",
                        "DISABLED",
                        "IN_APPEAL",
                        "PENDING_DELETION",
                        "DELETED",
                        "ARCHIVED",
                        "LIMIT_EXCEEDED",
                        "LOCKED",
                        "FLAGGED",
                        "REINSTATED"
                      ],
                      "type": "string",
                      "description": "Estado en Meta, p. ej., `APPROVED`, `PENDING`, `REJECTED`."
                    },
                    "rejected_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del rechazo, cuando lo hay."
                    },
                    "quality_score": {
                      "enum": [
                        "GREEN",
                        "YELLOW",
                        "RED",
                        "UNKNOWN"
                      ],
                      "type": "string",
                      "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                    },
                    "parameter_format": {
                      "enum": [
                        "POSITIONAL",
                        "NAMED"
                      ],
                      "type": "string",
                      "description": "Formato de las variables: `POSITIONAL` o `NAMED`."
                    },
                    "components": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      },
                      "description": "Componentes en el formato de Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                    },
                    "last_synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última lectura en Meta (ISO 8601, UTC)."
                    },
                    "status_updated_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último cambio de estado (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó en Messajo (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Obtener una plantilla",
        "description": "Devuelve la plantilla con estado, categoría y componentes. Permiso: `read`.",
        "tags": [
          "templates"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la plantilla en Messajo (`tpl_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La plantilla.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la plantilla en Messajo (`tpl_…`).",
                      "examples": [
                        "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Cuenta de WhatsApp Business (WABA) de la plantilla."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la plantilla en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre (minúsculas, números y `_`)."
                    },
                    "language": {
                      "type": "string",
                      "description": "Idioma, p. ej., `es`."
                    },
                    "category": {
                      "enum": [
                        "MARKETING",
                        "UTILITY",
                        "AUTHENTICATION"
                      ],
                      "type": "string",
                      "description": "Categoría: `MARKETING`, `UTILITY` o `AUTHENTICATION`."
                    },
                    "previous_category": {
                      "anyOf": [
                        {
                          "enum": [
                            "MARKETING",
                            "UTILITY",
                            "AUTHENTICATION"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Categoría anterior, cuando Meta la reclasificó."
                    },
                    "status": {
                      "enum": [
                        "APPROVED",
                        "PENDING",
                        "REJECTED",
                        "PAUSED",
                        "DISABLED",
                        "IN_APPEAL",
                        "PENDING_DELETION",
                        "DELETED",
                        "ARCHIVED",
                        "LIMIT_EXCEEDED",
                        "LOCKED",
                        "FLAGGED",
                        "REINSTATED"
                      ],
                      "type": "string",
                      "description": "Estado en Meta, p. ej., `APPROVED`, `PENDING`, `REJECTED`."
                    },
                    "rejected_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del rechazo, cuando lo hay."
                    },
                    "quality_score": {
                      "enum": [
                        "GREEN",
                        "YELLOW",
                        "RED",
                        "UNKNOWN"
                      ],
                      "type": "string",
                      "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                    },
                    "parameter_format": {
                      "enum": [
                        "POSITIONAL",
                        "NAMED"
                      ],
                      "type": "string",
                      "description": "Formato de las variables: `POSITIONAL` o `NAMED`."
                    },
                    "components": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      },
                      "description": "Componentes en el formato de Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                    },
                    "last_synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última lectura en Meta (ISO 8601, UTC)."
                    },
                    "status_updated_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último cambio de estado (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó en Messajo (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 plantilla",
        "description": "Edita los componentes o la categoría. Meta solo permite editar plantillas `APPROVED`, `REJECTED` o `PAUSED`, y una aprobada no cambia de categoría. Permiso: `templates`.",
        "tags": [
          "templates"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la plantilla en Messajo (`tpl_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "category": {
                    "enum": [
                      "MARKETING",
                      "UTILITY",
                      "AUTHENTICATION"
                    ],
                    "type": "string",
                    "description": "Categoría: `MARKETING`, `UTILITY` o `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 en el formato de Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La plantilla actualizada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la plantilla en Messajo (`tpl_…`).",
                      "examples": [
                        "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Cuenta de WhatsApp Business (WABA) de la plantilla."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la plantilla en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre (minúsculas, números y `_`)."
                    },
                    "language": {
                      "type": "string",
                      "description": "Idioma, p. ej., `es`."
                    },
                    "category": {
                      "enum": [
                        "MARKETING",
                        "UTILITY",
                        "AUTHENTICATION"
                      ],
                      "type": "string",
                      "description": "Categoría: `MARKETING`, `UTILITY` o `AUTHENTICATION`."
                    },
                    "previous_category": {
                      "anyOf": [
                        {
                          "enum": [
                            "MARKETING",
                            "UTILITY",
                            "AUTHENTICATION"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Categoría anterior, cuando Meta la reclasificó."
                    },
                    "status": {
                      "enum": [
                        "APPROVED",
                        "PENDING",
                        "REJECTED",
                        "PAUSED",
                        "DISABLED",
                        "IN_APPEAL",
                        "PENDING_DELETION",
                        "DELETED",
                        "ARCHIVED",
                        "LIMIT_EXCEEDED",
                        "LOCKED",
                        "FLAGGED",
                        "REINSTATED"
                      ],
                      "type": "string",
                      "description": "Estado en Meta, p. ej., `APPROVED`, `PENDING`, `REJECTED`."
                    },
                    "rejected_reason": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del rechazo, cuando lo hay."
                    },
                    "quality_score": {
                      "enum": [
                        "GREEN",
                        "YELLOW",
                        "RED",
                        "UNKNOWN"
                      ],
                      "type": "string",
                      "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                    },
                    "parameter_format": {
                      "enum": [
                        "POSITIONAL",
                        "NAMED"
                      ],
                      "type": "string",
                      "description": "Formato de las variables: `POSITIONAL` o `NAMED`."
                    },
                    "components": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      },
                      "description": "Componentes en el formato de Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                    },
                    "last_synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última lectura en Meta (ISO 8601, UTC)."
                    },
                    "status_updated_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último cambio de estado (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó en Messajo (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Eliminar plantilla",
        "description": "Elimina la plantilla en Meta y en Messajo. Permiso: `templates`.",
        "tags": [
          "templates"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la plantilla en Messajo (`tpl_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmación de la eliminación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la plantilla en Messajo (`tpl_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `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 plantillas",
        "description": "Lee ahora en Meta todas las plantillas de la cuenta de la conexión (Messajo ya lo hace cada día). Una plantilla que desapareció de Meta se marca como eliminada. Permiso: `templates`.",
        "tags": [
          "templates"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexión cuya cuenta de WhatsApp se usa. Opcional con una clave de conexión (usa la conexión de la clave)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cuántas plantillas llegaron y cuántas salieron.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "synced": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Plantillas leídas de Meta."
                    },
                    "deleted": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Plantillas marcadas como eliminadas."
                    }
                  },
                  "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": "Subir medio",
        "description": "Guarda un archivo (`multipart/form-data`) para usar después en `POST /messages` (`media_id`) o como foto del perfil. El tipo se lee de los bytes y debe caber en el límite de Meta. `convert=voice` convierte audio a OGG/Opus (mensaje de voz) y devuelve el medio convertido. Permiso: `send`.",
        "tags": [
          "media"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "El archivo."
                  },
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexión del medio. Opcional con una clave de conexión (usa la conexión de la clave)."
                  },
                  "convert": {
                    "enum": [
                      "voice"
                    ],
                    "type": "string",
                    "description": "`voice`: convierte a mensaje de voz (OGG/Opus)."
                  },
                  "purpose": {
                    "enum": [
                      "message",
                      "publication"
                    ],
                    "type": "string",
                    "description": "`message` (por defecto) o `publication`: aplica los límites del canal para esa finalidad (publicación de Instagram: JPEG hasta 8 MiB, video hasta 300 MiB)."
                  }
                },
                "required": [
                  "file"
                ]
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "El archivo."
                  },
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexión del medio. Opcional con una clave de conexión (usa la conexión de la clave)."
                  },
                  "convert": {
                    "enum": [
                      "voice"
                    ],
                    "type": "string",
                    "description": "`voice`: convierte a mensaje de voz (OGG/Opus)."
                  },
                  "purpose": {
                    "enum": [
                      "message",
                      "publication"
                    ],
                    "type": "string",
                    "description": "`message` (por defecto) o `publication`: aplica los límites del canal para esa finalidad (publicación de Instagram: JPEG hasta 8 MiB, video hasta 300 MiB)."
                  }
                },
                "required": [
                  "file"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El medio guardado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del medio (`med_…`).",
                      "examples": [
                        "med_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión del medio. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "mime_type": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tipo del archivo, p. ej., `image/jpeg`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre del archivo, cuando lo hay."
                    },
                    "size_bytes": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tamaño en bytes."
                    },
                    "sha256": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hash SHA-256 del contenido."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "stored",
                        "failed",
                        "purging"
                      ],
                      "type": "string",
                      "description": "Estado: `pending`, `stored` o `failed`."
                    },
                    "origin": {
                      "enum": [
                        "inbound",
                        "upload",
                        "converted"
                      ],
                      "type": "string",
                      "description": "Origen: `inbound` (recibido), `upload` o `converted`."
                    },
                    "converted_from_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Medio original, cuando este es una conversión."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se guardó el medio (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": "Obtener un medio",
        "description": "Devuelve los datos del medio (tipo, tamaño, estado). Permiso: `read`.",
        "tags": [
          "media"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del medio (`med_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El medio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del medio (`med_…`).",
                      "examples": [
                        "med_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión del medio. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "mime_type": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tipo del archivo, p. ej., `image/jpeg`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre del archivo, cuando lo hay."
                    },
                    "size_bytes": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tamaño en bytes."
                    },
                    "sha256": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Hash SHA-256 del contenido."
                    },
                    "status": {
                      "enum": [
                        "pending",
                        "stored",
                        "failed",
                        "purging"
                      ],
                      "type": "string",
                      "description": "Estado: `pending`, `stored` o `failed`."
                    },
                    "origin": {
                      "enum": [
                        "inbound",
                        "upload",
                        "converted"
                      ],
                      "type": "string",
                      "description": "Origen: `inbound` (recibido), `upload` o `converted`."
                    },
                    "converted_from_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Medio original, cuando este es una conversión."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se guardó el medio (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": "Eliminar medio",
        "description": "Borra el archivo de Messajo y, si ya se había subido, intenta borrarlo también en Meta (allí vence solo en 30 días). Permiso: `send`.",
        "tags": [
          "media"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del medio (`med_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmación de la eliminación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del medio (`med_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `true`."
                    },
                    "meta_deleted": {
                      "type": "boolean",
                      "description": "Si también salió de 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": "Descargar un medio",
        "description": "Devuelve los bytes del medio. Un medio recibido que aún no se descargó de Meta se descarga en el momento. Permiso: `read`.",
        "tags": [
          "media"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del medio (`med_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El archivo.",
            "content": {
              "*/*": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "*/*",
                  "description": "El archivo."
                }
              }
            },
            "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": "Crear enlace temporal",
        "description": "Genera un enlace firmado para descargar el medio sin clave, válido de 60 segundos a 7 días (por defecto 1 hora). Permiso: `read`.",
        "tags": [
          "media"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del medio (`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": "Validez del enlace, de 60 a 604 800 segundos."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El enlace y cuándo vence.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "description": "Enlace firmado."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Cuándo vence el enlace (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 enlaces de conexión",
        "description": "Lista los enlaces que permiten a una persona de fuera (sin cuenta en Messajo) conectar un número a la organización. Permiso: `admin`. Requiere una clave de la organización.",
        "tags": [
          "connection-links"
        ],
        "responses": {
          "200": {
            "description": "Los enlaces de conexión.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del enlace (`clk_…`).",
                            "examples": [
                              "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "channel": {
                            "enum": [
                              "whatsapp",
                              "instagram",
                              "messenger"
                            ],
                            "type": "string",
                            "description": "Canal a conectar (por ahora, `whatsapp`)."
                          },
                          "mode": {
                            "anyOf": [
                              {
                                "enum": [
                                  "coex",
                                  "api_only",
                                  "any"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Modo: `coex`, `api_only` o `any` (la persona elige)."
                          },
                          "label": {
                            "type": "string",
                            "description": "Nombre del enlace, para la organización."
                          },
                          "token_last4": {
                            "type": "string",
                            "description": "Últimos 4 caracteres del token."
                          },
                          "expires_at": {
                            "type": "string",
                            "description": "Cuándo vence el enlace (ISO 8601, UTC)."
                          },
                          "reusable": {
                            "type": "boolean",
                            "description": "`true` = vale para varios números; `false` = uso único."
                          },
                          "uses_count": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Conexiones ya hechas con el enlace."
                          },
                          "has_password": {
                            "type": "boolean",
                            "description": "Si el enlace pide contraseña."
                          },
                          "locale": {
                            "type": "string",
                            "description": "Idioma de la página y del correo: `pt-BR`, `en-US` o `es`."
                          },
                          "reconnect_connection_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conexión a reconectar, cuando el enlace es de reconexión."
                          },
                          "recipient_email": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Correo al que va el enlace."
                          },
                          "status": {
                            "enum": [
                              "active",
                              "used",
                              "expired",
                              "revoked"
                            ],
                            "type": "string",
                            "description": "Estado: `active`, `used`, `expired` o `revoked`."
                          },
                          "last_sent_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último envío por correo (ISO 8601, UTC)."
                          },
                          "last_used_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último uso (ISO 8601, UTC)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó el enlace (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Crear enlace de conexión",
        "description": "Crea un enlace público de conexión, con validez de 1 hora a 30 días, contraseña opcional y uso único o reutilizable. La `url` aparece solo en esta respuesta (y en el correo, si se informa `recipient_email`): Messajo guarda solo el hash del token. Para reconectar un número, informe `reconnect_connection_id`. Permiso: `admin`. Requiere una clave de la organización.",
        "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 ahora, `whatsapp`)."
                  },
                  "mode": {
                    "enum": [
                      "coex",
                      "api_only",
                      "any"
                    ],
                    "type": "string",
                    "description": "Modo: `coex`, `api_only` o `any` (la persona elige)."
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Nombre del enlace, para la organización."
                  },
                  "expires_in_hours": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 720,
                    "default": 168,
                    "description": "Validez en horas, de 1 a 720 (por defecto 168)."
                  },
                  "reusable": {
                    "type": "boolean",
                    "default": false,
                    "description": "`true` = vale para varios números; `false` = uso único."
                  },
                  "password": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 128,
                    "description": "Contraseña opcional, de 8 a 128 caracteres."
                  },
                  "locale": {
                    "enum": [
                      "pt-BR",
                      "en-US",
                      "es"
                    ],
                    "type": "string",
                    "description": "Idioma de la página y del correo: `pt-BR`, `en-US` o `es`."
                  },
                  "reconnect_connection_id": {
                    "type": "string",
                    "description": "Conexión a reconectar, cuando el enlace es de reconexión."
                  },
                  "recipient_email": {
                    "type": "string",
                    "maxLength": 254,
                    "format": "email",
                    "description": "Correo al que va el enlace."
                  }
                },
                "required": [
                  "label",
                  "locale"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El enlace creado, con la `url`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del enlace (`clk_…`).",
                      "examples": [
                        "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal a conectar (por ahora, `whatsapp`)."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only",
                            "any"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo: `coex`, `api_only` o `any` (la persona elige)."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del enlace, para la organización."
                    },
                    "token_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del token."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Cuándo vence el enlace (ISO 8601, UTC)."
                    },
                    "reusable": {
                      "type": "boolean",
                      "description": "`true` = vale para varios números; `false` = uso único."
                    },
                    "uses_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Conexiones ya hechas con el enlace."
                    },
                    "has_password": {
                      "type": "boolean",
                      "description": "Si el enlace pide contraseña."
                    },
                    "locale": {
                      "type": "string",
                      "description": "Idioma de la página y del correo: `pt-BR`, `en-US` o `es`."
                    },
                    "reconnect_connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión a reconectar, cuando el enlace es de reconexión."
                    },
                    "recipient_email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Correo al que va el enlace."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "used",
                        "expired",
                        "revoked"
                      ],
                      "type": "string",
                      "description": "Estado: `active`, `used`, `expired` o `revoked`."
                    },
                    "last_sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último envío por correo (ISO 8601, UTC)."
                    },
                    "last_used_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último uso (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó el enlace (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (ISO 8601, UTC)."
                    },
                    "url": {
                      "type": "string",
                      "description": "Dirección pública del enlace. Solo aparece al crear o 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": "Obtener un enlace de conexión",
        "description": "Devuelve el enlace, sin el token. Permiso: `admin`. Requiere una clave de la organización.",
        "tags": [
          "connection-links"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del enlace (`clk_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El enlace de conexión.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del enlace (`clk_…`).",
                      "examples": [
                        "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal a conectar (por ahora, `whatsapp`)."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only",
                            "any"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo: `coex`, `api_only` o `any` (la persona elige)."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del enlace, para la organización."
                    },
                    "token_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del token."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Cuándo vence el enlace (ISO 8601, UTC)."
                    },
                    "reusable": {
                      "type": "boolean",
                      "description": "`true` = vale para varios números; `false` = uso único."
                    },
                    "uses_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Conexiones ya hechas con el enlace."
                    },
                    "has_password": {
                      "type": "boolean",
                      "description": "Si el enlace pide contraseña."
                    },
                    "locale": {
                      "type": "string",
                      "description": "Idioma de la página y del correo: `pt-BR`, `en-US` o `es`."
                    },
                    "reconnect_connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión a reconectar, cuando el enlace es de reconexión."
                    },
                    "recipient_email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Correo al que va el enlace."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "used",
                        "expired",
                        "revoked"
                      ],
                      "type": "string",
                      "description": "Estado: `active`, `used`, `expired` o `revoked`."
                    },
                    "last_sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último envío por correo (ISO 8601, UTC)."
                    },
                    "last_used_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último uso (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó el enlace (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Revocar enlace de conexión",
        "description": "Revoca el enlace: deja de abrir. Permiso: `admin`. Requiere una clave de la organización.",
        "tags": [
          "connection-links"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del enlace (`clk_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El enlace revocado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del enlace (`clk_…`).",
                      "examples": [
                        "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal a conectar (por ahora, `whatsapp`)."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only",
                            "any"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo: `coex`, `api_only` o `any` (la persona elige)."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del enlace, para la organización."
                    },
                    "token_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del token."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Cuándo vence el enlace (ISO 8601, UTC)."
                    },
                    "reusable": {
                      "type": "boolean",
                      "description": "`true` = vale para varios números; `false` = uso único."
                    },
                    "uses_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Conexiones ya hechas con el enlace."
                    },
                    "has_password": {
                      "type": "boolean",
                      "description": "Si el enlace pide contraseña."
                    },
                    "locale": {
                      "type": "string",
                      "description": "Idioma de la página y del correo: `pt-BR`, `en-US` o `es`."
                    },
                    "reconnect_connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión a reconectar, cuando el enlace es de reconexión."
                    },
                    "recipient_email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Correo al que va el enlace."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "used",
                        "expired",
                        "revoked"
                      ],
                      "type": "string",
                      "description": "Estado: `active`, `used`, `expired` o `revoked`."
                    },
                    "last_sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último envío por correo (ISO 8601, UTC)."
                    },
                    "last_used_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último uso (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó el enlace (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 enlace por correo",
        "description": "Envía el enlace por correo, en el idioma del enlace. Genera un token nuevo: la URL anterior deja de valer. La contraseña nunca va en el correo. Permiso: `admin`. Requiere una clave de la organización.",
        "tags": [
          "connection-links"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del enlace (`clk_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "recipient_email": {
                    "type": "string",
                    "maxLength": 254,
                    "format": "email",
                    "description": "Correo al que va el enlace."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El enlace, con la `url` nueva.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del enlace (`clk_…`).",
                      "examples": [
                        "clk_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal a conectar (por ahora, `whatsapp`)."
                    },
                    "mode": {
                      "anyOf": [
                        {
                          "enum": [
                            "coex",
                            "api_only",
                            "any"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Modo: `coex`, `api_only` o `any` (la persona elige)."
                    },
                    "label": {
                      "type": "string",
                      "description": "Nombre del enlace, para la organización."
                    },
                    "token_last4": {
                      "type": "string",
                      "description": "Últimos 4 caracteres del token."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Cuándo vence el enlace (ISO 8601, UTC)."
                    },
                    "reusable": {
                      "type": "boolean",
                      "description": "`true` = vale para varios números; `false` = uso único."
                    },
                    "uses_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Conexiones ya hechas con el enlace."
                    },
                    "has_password": {
                      "type": "boolean",
                      "description": "Si el enlace pide contraseña."
                    },
                    "locale": {
                      "type": "string",
                      "description": "Idioma de la página y del correo: `pt-BR`, `en-US` o `es`."
                    },
                    "reconnect_connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conexión a reconectar, cuando el enlace es de reconexión."
                    },
                    "recipient_email": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Correo al que va el enlace."
                    },
                    "status": {
                      "enum": [
                        "active",
                        "used",
                        "expired",
                        "revoked"
                      ],
                      "type": "string",
                      "description": "Estado: `active`, `used`, `expired` o `revoked`."
                    },
                    "last_sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último envío por correo (ISO 8601, UTC)."
                    },
                    "last_used_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último uso (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó el enlace (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (ISO 8601, UTC)."
                    },
                    "url": {
                      "type": "string",
                      "description": "Dirección pública del enlace. Solo aparece al crear o 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": "Obtener perfil de mensajes",
        "description": "Lee en Meta el perfil de mensajes de la cuenta de Instagram o de la Página: ice breakers, menú fijo y, en Messenger, saludo y botón Empezar. Un campo sin configurar viene `null`. Permiso: `read`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram o de Messenger (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El perfil.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión de Instagram o de Messenger (`con_…`)."
                    },
                    "channel": {
                      "enum": [
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "`instagram` o `messenger`."
                    },
                    "ice_breakers": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Preguntas listas de la primera conversación, por idioma (`locale`, `questions[{ question, payload }]`)."
                    },
                    "persistent_menu": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Menú fijo, por idioma (`locale`, `items[]`, `composer_input_disabled` solo en Messenger)."
                    },
                    "greeting": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saludo antes del primer mensaje, por idioma (`locale`, `text` hasta 160, acepta `{{user_first_name}}`). Solo Messenger."
                    },
                    "get_started": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "payload": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "payload"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Botón Empezar (`payload`). Solo Messenger."
                    },
                    "synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se leyó el perfil de 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": "Cambiar perfil de mensajes",
        "description": "Guarda el perfil de mensajes de forma parcial: un campo ausente no cambia, `null` lo borra. Ice breakers: hasta 4 preguntas por idioma; menú fijo: hasta 20 elementos (`postback` o `web_url`); cada lista necesita el idioma `default`. `greeting` y `get_started` solo en Messenger (en Instagram: `422 type_not_supported_by_channel`); borrar `get_started` con el menú activo se rechaza. Permiso: `admin`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram o de 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": "Preguntas listas de la primera conversación, por idioma (`locale`, `questions[{ question, payload }]`)."
                  },
                  "persistent_menu": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "locale": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "locale"
                          ],
                          "additionalProperties": {}
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Menú fijo, por idioma (`locale`, `items[]`, `composer_input_disabled` solo en Messenger)."
                  },
                  "greeting": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "locale": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "locale"
                          ],
                          "additionalProperties": {}
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Saludo antes del primer mensaje, por idioma (`locale`, `text` hasta 160, acepta `{{user_first_name}}`). Solo Messenger."
                  },
                  "get_started": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "payload": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "payload"
                        ]
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Botón Empezar (`payload`). Solo Messenger."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El perfil releído de Meta.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión de Instagram o de Messenger (`con_…`)."
                    },
                    "channel": {
                      "enum": [
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "`instagram` o `messenger`."
                    },
                    "ice_breakers": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Preguntas listas de la primera conversación, por idioma (`locale`, `questions[{ question, payload }]`)."
                    },
                    "persistent_menu": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Menú fijo, por idioma (`locale`, `items[]`, `composer_input_disabled` solo en Messenger)."
                    },
                    "greeting": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "locale": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "locale"
                            ],
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Saludo antes del primer mensaje, por idioma (`locale`, `text` hasta 160, acepta `{{user_first_name}}`). Solo Messenger."
                    },
                    "get_started": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "payload": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "payload"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Botón Empezar (`payload`). Solo Messenger."
                    },
                    "synced_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se leyó el perfil de 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 flujos de bienvenida",
        "description": "Lista los flujos de bienvenida de la cuenta de Instagram (anuncios que llevan a Direct). Permiso: `read`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram o de Messenger (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Los flujos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del flujo en Meta."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nombre del flujo."
                          },
                          "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": "Mensajes del flujo, en orden."
                          },
                          "is_used_in_ad": {
                            "type": "boolean",
                            "description": "Flujo usado en un anuncio (no cambia ni se borra)."
                          }
                        },
                        "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": "Crear flujo de bienvenida",
        "description": "Crea un flujo de bienvenida de Instagram: nombre y mensajes con respuestas rápidas. Permiso: `admin`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram o de Messenger (`con_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Nombre del flujo."
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Texto del mensaje."
                        },
                        "quick_replies": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "title": {
                                "type": "string",
                                "description": "Texto del botón (hasta 20 caracteres)."
                              },
                              "payload": {
                                "type": "string",
                                "description": "Valor devuelto en el webhook cuando el contacto toca."
                              }
                            },
                            "required": [
                              "title",
                              "payload"
                            ]
                          },
                          "description": "Respuestas rápidas del mensaje (hasta 13)."
                        }
                      },
                      "required": [
                        "text"
                      ]
                    },
                    "description": "Mensajes del flujo, en orden."
                  }
                },
                "required": [
                  "name",
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El flujo creado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del flujo en 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": "Cambiar flujo de bienvenida",
        "description": "Reemplaza el nombre y los mensajes de un flujo. Un flujo usado en un anuncio no cambia (`409 welcome_flow_in_use`). Permiso: `admin`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram o de Messenger (`con_…`)."
            }
          },
          {
            "name": "flow_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del flujo en Meta."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Nombre del flujo."
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "text": {
                          "type": "string",
                          "description": "Texto del mensaje."
                        },
                        "quick_replies": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "title": {
                                "type": "string",
                                "description": "Texto del botón (hasta 20 caracteres)."
                              },
                              "payload": {
                                "type": "string",
                                "description": "Valor devuelto en el webhook cuando el contacto toca."
                              }
                            },
                            "required": [
                              "title",
                              "payload"
                            ]
                          },
                          "description": "Respuestas rápidas del mensaje (hasta 13)."
                        }
                      },
                      "required": [
                        "text"
                      ]
                    },
                    "description": "Mensajes del flujo, en orden."
                  }
                },
                "required": [
                  "name",
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El flujo cambiado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del flujo en 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": "Borrar flujo de bienvenida",
        "description": "Borra un flujo. Un flujo usado en un anuncio no se borra (`409 welcome_flow_in_use`). Permiso: `admin`.",
        "tags": [
          "messaging-profile"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram o de Messenger (`con_…`)."
            }
          },
          {
            "name": "flow_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del flujo en Meta."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del flujo en Meta."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `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 los posts de la cuenta de Instagram, en vivo desde Meta, del más nuevo al más antiguo, con tipo, descripción, enlace, me gusta y comentarios. Permiso: `read`.",
        "tags": [
          "posts"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de posts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del post (contenido) en Meta."
                          }
                        },
                        "required": [
                          "id"
                        ],
                        "additionalProperties": {},
                        "description": "Post como lo devuelve Meta: `id`, `caption`, `media_type`, `media_product_type`, `permalink`, `timestamp`, `like_count`, `comments_count`, `thumbnail_url`, `media_url`."
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Obtener un post",
        "description": "Devuelve un post de la cuenta, en vivo desde Meta. Post de otra cuenta: `404`. Permiso: `read`.",
        "tags": [
          "posts"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "post_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del post (contenido) en Meta."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El post.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del post (contenido) en Meta."
                    }
                  },
                  "required": [
                    "id"
                  ],
                  "additionalProperties": {},
                  "description": "Post como lo devuelve Meta: `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": "Cuota de publicación",
        "description": "Lee en Meta cuántas publicaciones hizo la cuenta en la ventana de la cuota (Meta limita por 24 h). Permiso: `read`.",
        "tags": [
          "posts"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La cuota.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "quota_usage": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Publicaciones hechas en la ventana de la cuota."
                    },
                    "quota_total": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Publicaciones permitidas en la ventana."
                    },
                    "quota_duration_s": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Duración de la ventana, en 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 comentarios de un post",
        "description": "Lista los comentarios de un post de Instagram, en vivo desde Meta, con las respuestas y el estado local (`private_replied_at`, `deleted_at`). Exige el permiso `instagram_manage_comments` de la cuenta (`403 instagram_scope_missing`). Permiso: `read`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "post_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del post (contenido) en Meta."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de comentarios.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id"
                        ],
                        "additionalProperties": {},
                        "description": "Comentario como lo devuelve Meta, con `comment_id`, `private_replied_at` y `deleted_at` de Messajo."
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Obtener un comentario",
        "description": "Devuelve un comentario o mención guardado por Messajo (`cmt_…`). Permiso: `read`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del comentario en Messajo (`cmt_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El comentario.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del comentario en Messajo (`cmt_…`).",
                      "examples": [
                        "cmt_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del comentario en Meta."
                    },
                    "kind": {
                      "enum": [
                        "comment",
                        "live_comment",
                        "mention"
                      ],
                      "type": "string",
                      "description": "`comment`, `live_comment` (de un en vivo) o `mention`."
                    },
                    "text": {
                      "type": "string",
                      "description": "Texto."
                    },
                    "parent_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Comentario padre (en Meta), cuando es respuesta."
                    },
                    "from": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "username": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "username"
                      ],
                      "description": "Quién lo escribió."
                    },
                    "from_self": {
                      "type": "boolean",
                      "description": "`true` cuando lo escribió la propia cuenta."
                    },
                    "post": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "product_type": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "product_type"
                      ],
                      "description": "Post del comentario: ID y tipo (`FEED`, `REELS`, `STORY`)."
                    },
                    "hidden": {
                      "type": "boolean",
                      "description": "Comentario oculto."
                    },
                    "reply_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Respuestas enviadas por Messajo."
                    },
                    "private_replied_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se envió la respuesta por Direct (ISO 8601, UTC)."
                    },
                    "deleted_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se borró (ISO 8601, UTC)."
                    },
                    "occurred_at": {
                      "type": "string",
                      "description": "Cuándo ocurrió (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": "Borrar un comentario",
        "description": "Borra un comentario en un contenido de la propia cuenta; en contenido de otra cuenta (mención): `409 comment_not_owned`. Genera `comment.deleted`. Permiso: `send`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del comentario en Messajo (`cmt_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del comentario en Messajo (`cmt_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `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 un comentario",
        "description": "Responde en público a un comentario (hasta 2200 caracteres). No es idempotente en Meta: usa `Idempotency-Key` para repetir sin duplicar. Genera `comment.replied`. Permiso: `send`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del comentario en 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 de la respuesta (hasta 2200 caracteres)."
                  }
                },
                "required": [
                  "message"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "La respuesta creada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la respuesta en 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 por Direct",
        "description": "Envía un mensaje por Direct a quien comentó: `text`, `buttons` o `cards`, en el mismo formato de `POST /messages`. Una vez por comentario (`409 private_reply_already_sent`), hasta 7 días después del comentario (`422 private_reply_window_closed`), sin depender de la ventana de 24 h. Abre la conversación con el contacto y genera `comment.private_replied` y `message.sent`. Permiso: `send`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del comentario en Messajo (`cmt_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "minLength": 1,
                    "description": "`text`, `buttons` o `cards`, con el campo del mismo nombre como en `POST /messages`."
                  }
                },
                "required": [
                  "type"
                ],
                "additionalProperties": {}
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El mensaje enviado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del mensaje en Messajo (`msg_…`)."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del mensaje en Meta (`wamid`)."
                    },
                    "conversation_id": {
                      "type": "string",
                      "description": "Conversación del mensaje."
                    },
                    "contact_id": {
                      "type": "string",
                      "description": "Contacto destinatario."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se guardó el mensaje (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 o mostrar un comentario",
        "description": "Oculta (`hidden: true`) o vuelve a mostrar un comentario. Genera `comment.hidden` o `comment.unhidden`. Permiso: `send`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "comment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del comentario en Messajo (`cmt_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "hidden": {
                    "type": "boolean",
                    "description": "Comentario oculto."
                  }
                },
                "required": [
                  "hidden"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El comentario actualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del comentario en Messajo (`cmt_…`).",
                      "examples": [
                        "cmt_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del comentario en Meta."
                    },
                    "kind": {
                      "enum": [
                        "comment",
                        "live_comment",
                        "mention"
                      ],
                      "type": "string",
                      "description": "`comment`, `live_comment` (de un en vivo) o `mention`."
                    },
                    "text": {
                      "type": "string",
                      "description": "Texto."
                    },
                    "parent_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Comentario padre (en Meta), cuando es respuesta."
                    },
                    "from": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "username": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "username"
                      ],
                      "description": "Quién lo escribió."
                    },
                    "from_self": {
                      "type": "boolean",
                      "description": "`true` cuando lo escribió la propia cuenta."
                    },
                    "post": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "product_type": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": [
                        "id",
                        "product_type"
                      ],
                      "description": "Post del comentario: ID y tipo (`FEED`, `REELS`, `STORY`)."
                    },
                    "hidden": {
                      "type": "boolean",
                      "description": "Comentario oculto."
                    },
                    "reply_count": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Respuestas enviadas por Messajo."
                    },
                    "private_replied_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se envió la respuesta por Direct (ISO 8601, UTC)."
                    },
                    "deleted_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se borró (ISO 8601, UTC)."
                    },
                    "occurred_at": {
                      "type": "string",
                      "description": "Cuándo ocurrió (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 menciones",
        "description": "Lista las menciones a la cuenta (en comentarios, descripciones y stories) guardadas por Messajo, de la más nueva a la más antigua. Permiso: `read`.",
        "tags": [
          "comments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de menciones.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la mención en Messajo (`cmt_…`)."
                          },
                          "source": {
                            "enum": [
                              "comment",
                              "caption",
                              "story"
                            ],
                            "type": "string",
                            "description": "Dónde se mencionó la cuenta: `comment`, `caption` o `story`."
                          },
                          "post_id": {
                            "type": "string",
                            "description": "ID del post (contenido) en Meta."
                          },
                          "comment_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del comentario en Meta."
                          },
                          "from": {
                            "type": "object",
                            "properties": {
                              "username": {
                                "anyOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ]
                              }
                            },
                            "required": [
                              "username"
                            ],
                            "description": "Quién lo escribió."
                          },
                          "text": {
                            "type": "string",
                            "description": "Texto."
                          },
                          "occurred_at": {
                            "type": "string",
                            "description": "Cuándo ocurrió (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "source",
                          "post_id",
                          "comment_id",
                          "from",
                          "text",
                          "occurred_at"
                        ],
                        "description": "Mención a la cuenta."
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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 de la cuenta",
        "description": "Métricas de la cuenta de Instagram. `period=day`: `reach`, `views`, `accounts_engaged`, `total_interactions`, `likes`, `comments`, `shares`, `saves`, `replies`, `reposts`, `follows_and_unfollows`, `profile_links_taps`. `period=lifetime` con `timeframe` (`this_week`, `this_month`): `follower_demographics`, `engaged_audience_demographics`. `impressions` fue retirada por Meta (`422 validation_failed`). Resultado guardado por 15 min. Exige `instagram_manage_insights`. Permiso: `read`.",
        "tags": [
          "insights"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "metric",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Métricas separadas por coma."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "period",
            "in": "query",
            "required": true,
            "schema": {
              "enum": [
                "day",
                "lifetime"
              ],
              "type": "string",
              "description": "`day` o `lifetime`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "metric_type",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "time_series",
                "total_value"
              ],
              "type": "string",
              "description": "`time_series` o `total_value`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "breakdown",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "description": "Desglose de la métrica (por ejemplo `city`, `age`, `gender`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "timeframe",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "description": "Ventana de las demográficas: `this_week` o `this_month`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Inicio (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fin (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Las métricas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "metric": {
                            "type": "string",
                            "description": "Nombre de la métrica."
                          },
                          "period": {
                            "type": "string",
                            "description": "`day` o `lifetime`."
                          },
                          "total_value": {
                            "description": "Valor total, cuando Meta lo devuelve."
                          },
                          "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": "Desgloses, como los devuelve Meta."
                          }
                        },
                        "required": [
                          "metric",
                          "period",
                          "values",
                          "breakdowns"
                        ],
                        "description": "Una 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 un post",
        "description": "Métricas de un post, según su tipo (feed, Reels o story). Una story vencida sale del último registro guardado (`source: snapshot`). Hijo de carrusel o audiencia pequeña: `422 insights_not_available`. Permiso: `read`.",
        "tags": [
          "insights"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Conexión de Instagram (`con_…`)."
            }
          },
          {
            "name": "post_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del post (contenido) en Meta."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Las métricas del post.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "media_id": {
                      "type": "string",
                      "description": "ID del post (contenido) en Meta."
                    },
                    "product_type": {
                      "enum": [
                        "FEED",
                        "REELS",
                        "STORY"
                      ],
                      "type": "string",
                      "description": "Tipo de post: `FEED`, `REELS` o `STORY`."
                    },
                    "source": {
                      "enum": [
                        "live",
                        "snapshot"
                      ],
                      "type": "string",
                      "description": "`live` (leído ahora) o `snapshot` (registro de una story ya vencida)."
                    },
                    "captured_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se tomó el registro (ISO 8601, UTC)."
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "metric": {
                            "type": "string",
                            "description": "Nombre de la métrica."
                          },
                          "period": {
                            "type": "string",
                            "description": "`day` o `lifetime`."
                          },
                          "total_value": {
                            "description": "Valor total, cuando Meta lo devuelve."
                          },
                          "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": "Desgloses, como los devuelve Meta."
                          }
                        },
                        "required": [
                          "metric",
                          "period",
                          "values",
                          "breakdowns"
                        ],
                        "description": "Una 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": "Crear publicación",
        "description": "Publica en Instagram al momento o la programa (`scheduled_at` entre 1 min y 75 días adelante). `photo`: 1 imagen; `video` y `reel`: 1 video (se vuelve Reels); `carousel`: 2 a 20 elementos; `story`: 1 imagen o video. Descripción hasta 2200 caracteres, 30 hashtags y 20 menciones. Cada elemento es un `media_id` (de `POST /media` con `purpose=publication`) o una `url` https pública. Imagen PNG/WebP se convierte a JPEG. La publicación nunca se repite a ciegas. Usa `Idempotency-Key` para no crear dos. Genera `publication.published` o `publication.failed`. Exige `instagram_content_publish`. Permiso: `send`.",
        "tags": [
          "publications"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Conexión de Instagram (`con_…`)."
                  },
                  "type": {
                    "enum": [
                      "photo",
                      "video",
                      "carousel",
                      "reel",
                      "story"
                    ],
                    "type": "string",
                    "description": "`photo`, `video`, `carousel`, `reel` o `story`."
                  },
                  "caption": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Descripción."
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "properties": {
                        "media_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Multimedia guardada en Messajo (`med_…`)."
                        },
                        "url": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL https pública que Meta descarga."
                        },
                        "alt_text": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Texto alternativo de la imagen."
                        },
                        "user_tags": {
                          "type": "array",
                          "items": {},
                          "description": "Etiquetas de personas, en el formato de Meta."
                        }
                      },
                      "description": "Un contenido: `media_id` o `url`."
                    },
                    "description": "Contenidos de la publicación, en orden."
                  },
                  "scheduled_at": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "date-time",
                        "description": "Horario programado (ISO 8601); vacío o `null` = publicar ya."
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "share_to_feed": {
                    "type": "boolean",
                    "description": "El Reels también aparece en el feed."
                  },
                  "cover": {
                    "type": "string",
                    "minLength": 1,
                    "description": "URL de la portada del Reels."
                  },
                  "thumb_offset_ms": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Fotograma de la portada del video, en ms."
                  },
                  "collaborators": {
                    "type": "array",
                    "maxItems": 3,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": "Hasta 3 cuentas colaboradoras (@)."
                  },
                  "location_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID del lugar en Meta."
                  },
                  "audio_name": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Nombre del audio del Reels."
                  }
                },
                "required": [
                  "type",
                  "items"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "La publicación creada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la publicación (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión de Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` o `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción."
                    },
                    "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": "Contenidos de la publicación, en orden."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "El Reels también aparece en el feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL de la portada del Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Fotograma de la portada del video, en ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Hasta 3 cuentas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID del lugar en Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nombre del audio del Reels."
                        }
                      },
                      "description": "Opciones de la publicación (`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` o `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horario programado (ISO 8601); vacío o `null` = publicar ya."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del post publicado en Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enlace del post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se publicó (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último error, cuando falló."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Intentos hechos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 publicaciones",
        "description": "Lista las publicaciones de la organización, de las más nuevas a las más antiguas, con filtros por conexión, estado y horario (`since`/`until`). Permiso: `read`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Conexión de 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` o `canceled`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Programadas o creadas desde (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Programadas o creadas hasta (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Las publicaciones.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la publicación (`pub_…`).",
                            "examples": [
                              "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "Conexión de Instagram (`con_…`)."
                          },
                          "type": {
                            "enum": [
                              "photo",
                              "video",
                              "carousel",
                              "reel",
                              "story"
                            ],
                            "type": "string",
                            "description": "`photo`, `video`, `carousel`, `reel` o `story`."
                          },
                          "caption": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Descripción."
                          },
                          "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": "Contenidos de la publicación, en orden."
                          },
                          "options": {
                            "type": "object",
                            "properties": {
                              "share_to_feed": {
                                "type": "boolean",
                                "description": "El Reels también aparece en el feed."
                              },
                              "cover": {
                                "type": "string",
                                "minLength": 1,
                                "description": "URL de la portada del Reels."
                              },
                              "thumb_offset_ms": {
                                "type": "integer",
                                "minimum": 0,
                                "maximum": 9007199254740991,
                                "description": "Fotograma de la portada del video, en ms."
                              },
                              "collaborators": {
                                "type": "array",
                                "maxItems": 3,
                                "items": {
                                  "type": "string",
                                  "minLength": 1
                                },
                                "description": "Hasta 3 cuentas colaboradoras (@)."
                              },
                              "location_id": {
                                "type": "string",
                                "minLength": 1,
                                "description": "ID del lugar en Meta."
                              },
                              "audio_name": {
                                "type": "string",
                                "minLength": 1,
                                "description": "Nombre del audio del Reels."
                              }
                            },
                            "description": "Opciones de la publicación (`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` o `canceled`."
                          },
                          "scheduled_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Horario programado (ISO 8601); vacío o `null` = publicar ya."
                          },
                          "external_media_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del post publicado en Meta."
                          },
                          "permalink": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Enlace del post publicado."
                          },
                          "published_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo se publicó (ISO 8601, UTC)."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último error, cuando falló."
                          },
                          "attempts": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Intentos hechos."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Creación (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Obtener una publicación",
        "description": "Devuelve la publicación con estado, intentos, error y, ya publicada, el ID y el enlace del post. Permiso: `read`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la publicación (`pub_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La publicación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la publicación (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión de Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` o `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción."
                    },
                    "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": "Contenidos de la publicación, en orden."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "El Reels también aparece en el feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL de la portada del Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Fotograma de la portada del video, en ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Hasta 3 cuentas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID del lugar en Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nombre del audio del Reels."
                        }
                      },
                      "description": "Opciones de la publicación (`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` o `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horario programado (ISO 8601); vacío o `null` = publicar ya."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del post publicado en Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enlace del post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se publicó (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último error, cuando falló."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Intentos hechos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Cambiar publicación programada",
        "description": "Cambia descripción, elementos, horario u opciones de una publicación `scheduled` o `queued`; un campo ausente no cambia. `scheduled_at: null` publica ya. Otros estados: `409 publication_not_editable`. Permiso: `send`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la publicación (`pub_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "caption": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Descripción."
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "properties": {
                        "media_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Multimedia guardada en Messajo (`med_…`)."
                        },
                        "url": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL https pública que Meta descarga."
                        },
                        "alt_text": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Texto alternativo de la imagen."
                        },
                        "user_tags": {
                          "type": "array",
                          "items": {},
                          "description": "Etiquetas de personas, en el formato de Meta."
                        }
                      },
                      "description": "Un contenido: `media_id` o `url`."
                    },
                    "description": "Contenidos de la publicación, en orden."
                  },
                  "scheduled_at": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "date-time",
                        "description": "Horario programado (ISO 8601); vacío o `null` = publicar ya."
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "share_to_feed": {
                    "type": "boolean",
                    "description": "El Reels también aparece en el feed."
                  },
                  "cover": {
                    "type": "string",
                    "minLength": 1,
                    "description": "URL de la portada del Reels."
                  },
                  "thumb_offset_ms": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Fotograma de la portada del video, en ms."
                  },
                  "collaborators": {
                    "type": "array",
                    "maxItems": 3,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": "Hasta 3 cuentas colaboradoras (@)."
                  },
                  "location_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID del lugar en Meta."
                  },
                  "audio_name": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Nombre del audio del Reels."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La publicación cambiada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la publicación (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión de Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` o `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción."
                    },
                    "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": "Contenidos de la publicación, en orden."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "El Reels también aparece en el feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL de la portada del Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Fotograma de la portada del video, en ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Hasta 3 cuentas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID del lugar en Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nombre del audio del Reels."
                        }
                      },
                      "description": "Opciones de la publicación (`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` o `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horario programado (ISO 8601); vacío o `null` = publicar ya."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del post publicado en Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enlace del post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se publicó (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último error, cuando falló."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Intentos hechos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 publicación",
        "description": "Cancela una publicación `scheduled` o `queued`. Otros estados: `409 publication_not_editable`. Permiso: `send`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la publicación (`pub_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La publicación cancelada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la publicación (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión de Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` o `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción."
                    },
                    "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": "Contenidos de la publicación, en orden."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "El Reels también aparece en el feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL de la portada del Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Fotograma de la portada del video, en ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Hasta 3 cuentas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID del lugar en Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nombre del audio del Reels."
                        }
                      },
                      "description": "Opciones de la publicación (`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` o `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horario programado (ISO 8601); vacío o `null` = publicar ya."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del post publicado en Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enlace del post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se publicó (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último error, cuando falló."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Intentos hechos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Reintentar",
        "description": "Vuelve a poner en la cola una publicación `failed`, con contenedores nuevos. No vale cuando el resultado quedó incierto. Permiso: `send`.",
        "tags": [
          "publications"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la publicación (`pub_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La publicación en la cola.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la publicación (`pub_…`).",
                      "examples": [
                        "pub_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "Conexión de Instagram (`con_…`)."
                    },
                    "type": {
                      "enum": [
                        "photo",
                        "video",
                        "carousel",
                        "reel",
                        "story"
                      ],
                      "type": "string",
                      "description": "`photo`, `video`, `carousel`, `reel` o `story`."
                    },
                    "caption": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción."
                    },
                    "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": "Contenidos de la publicación, en orden."
                    },
                    "options": {
                      "type": "object",
                      "properties": {
                        "share_to_feed": {
                          "type": "boolean",
                          "description": "El Reels también aparece en el feed."
                        },
                        "cover": {
                          "type": "string",
                          "minLength": 1,
                          "description": "URL de la portada del Reels."
                        },
                        "thumb_offset_ms": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991,
                          "description": "Fotograma de la portada del video, en ms."
                        },
                        "collaborators": {
                          "type": "array",
                          "maxItems": 3,
                          "items": {
                            "type": "string",
                            "minLength": 1
                          },
                          "description": "Hasta 3 cuentas colaboradoras (@)."
                        },
                        "location_id": {
                          "type": "string",
                          "minLength": 1,
                          "description": "ID del lugar en Meta."
                        },
                        "audio_name": {
                          "type": "string",
                          "minLength": 1,
                          "description": "Nombre del audio del Reels."
                        }
                      },
                      "description": "Opciones de la publicación (`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` o `canceled`."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Horario programado (ISO 8601); vacío o `null` = publicar ya."
                    },
                    "external_media_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del post publicado en Meta."
                    },
                    "permalink": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enlace del post publicado."
                    },
                    "published_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se publicó (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último error, cuando falló."
                    },
                    "attempts": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Intentos hechos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 conversaciones",
        "description": "Lista las conversaciones de la organización, del último mensaje más reciente al más antiguo. Una clave limitada a conexiones solo ve sus conversaciones. Permiso: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "Cursor opaco de la página siguiente: el `next_cursor` de la respuesta anterior, con los mismos filtros. Alterado o de otra ruta → `400 invalid_cursor`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "contact_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del contacto."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "window",
            "in": "query",
            "schema": {
              "enum": [
                "open",
                "closed"
              ],
              "type": "string",
              "description": "`open` = ventana de atención abierta; `closed` = cerrada."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Último mensaje desde esta fecha (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Último mensaje hasta esta fecha (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de conversaciones.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la conversación."
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID de la conexión."
                          },
                          "channel": {
                            "enum": [
                              "whatsapp",
                              "instagram",
                              "messenger"
                            ],
                            "type": "string",
                            "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                          },
                          "contact": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "description": "ID del contacto."
                              },
                              "display_name": {
                                "anyOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ],
                                "description": "Nombre del contacto, cuando se conoce."
                              }
                            },
                            "required": [
                              "id",
                              "display_name"
                            ],
                            "description": "Contacto de la conversación."
                          },
                          "last_message_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último mensaje de la conversación (ISO 8601, UTC)."
                          },
                          "last_inbound_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último mensaje recibido del contacto (ISO 8601, UTC)."
                          },
                          "last_outbound_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último mensaje enviado al contacto (ISO 8601, UTC)."
                          },
                          "window_ends_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Fin de la ventana de atención de 24 h (ISO 8601, UTC)."
                          },
                          "extended_window_ends_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Fin de la ventana extendida (ISO 8601, UTC); `null` = sin ventana extendida."
                          },
                          "extended_window_kind": {
                            "anyOf": [
                              {
                                "enum": [
                                  "human_agent",
                                  "ad_referral"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Tipo de ventana extendida: `human_agent` o `ad_referral`."
                          },
                          "window_open": {
                            "type": "boolean",
                            "description": "`true` mientras la ventana de atención está abierta."
                          },
                          "last_sequence": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Número de secuencia del último evento de la conversación."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Fecha de creación (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Obtener conversación",
        "description": "Devuelve una conversación, con su ventana de atención. Permiso: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conversación."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La conversación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la conversación."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión."
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                    },
                    "contact": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "ID del contacto."
                        },
                        "display_name": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Nombre del contacto, cuando se conoce."
                        }
                      },
                      "required": [
                        "id",
                        "display_name"
                      ],
                      "description": "Contacto de la conversación."
                    },
                    "last_message_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último mensaje de la conversación (ISO 8601, UTC)."
                    },
                    "last_inbound_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último mensaje recibido del contacto (ISO 8601, UTC)."
                    },
                    "last_outbound_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Último mensaje enviado al contacto (ISO 8601, UTC)."
                    },
                    "window_ends_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fin de la ventana de atención de 24 h (ISO 8601, UTC)."
                    },
                    "extended_window_ends_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fin de la ventana extendida (ISO 8601, UTC); `null` = sin ventana extendida."
                    },
                    "extended_window_kind": {
                      "anyOf": [
                        {
                          "enum": [
                            "human_agent",
                            "ad_referral"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Tipo de ventana extendida: `human_agent` o `ad_referral`."
                    },
                    "window_open": {
                      "type": "boolean",
                      "description": "`true` mientras la ventana de atención está abierta."
                    },
                    "last_sequence": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Número de secuencia del último evento de la conversación."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (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 mensajes de la conversación",
        "description": "Lista los mensajes de una conversación dentro de la retención de la organización (por defecto: del más nuevo al más antiguo). Permiso: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conversación."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "Cursor opaco de la página siguiente: el `next_cursor` de la respuesta anterior, con los mismos filtros. Alterado o de otra ruta → `400 invalid_cursor`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "order",
            "in": "query",
            "schema": {
              "enum": [
                "desc",
                "asc"
              ],
              "type": "string",
              "default": "desc",
              "description": "Orden: `desc` (por defecto, el más nuevo primero) o `asc`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "enum": [
                "inbound",
                "outbound"
              ],
              "type": "string",
              "description": "Dirección: `inbound` (recibido) u `outbound` (enviado)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Tipo del contenido, p. ej. `text`, `image`, `template`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Inicio del intervalo (ISO 8601). Por defecto y como límite: ahora menos la retención de la organización."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Fin del intervalo (ISO 8601). Por defecto: ahora."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de mensajes.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del mensaje en Messajo (`msg_…`).",
                            "examples": [
                              "msg_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del mensaje en Meta; `null` antes de la aceptación."
                          },
                          "direction": {
                            "enum": [
                              "inbound",
                              "outbound"
                            ],
                            "type": "string",
                            "description": "Dirección: `inbound` (recibido) u `outbound` (enviado)."
                          },
                          "source": {
                            "enum": [
                              "customer",
                              "api",
                              "business_app",
                              "history",
                              "campaign"
                            ],
                            "type": "string",
                            "description": "Origen: `customer`, `api`, `business_app`, `history` o `campaign`."
                          },
                          "timestamp": {
                            "type": "string",
                            "description": "Cuándo ocurrió el mensaje (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": "Contenido normalizado (el mismo de los 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: respuesta, reenvío, anuncio de origen; `null` = sin contexto."
                          },
                          "conversation_id": {
                            "type": "string",
                            "description": "ID de la conversación."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del contacto."
                          },
                          "status": {
                            "enum": [
                              "received",
                              "queued",
                              "sent",
                              "delivered",
                              "read",
                              "played",
                              "failed",
                              "deleted"
                            ],
                            "type": "string",
                            "description": "Estado del mensaje."
                          },
                          "sent_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Enviado (ISO 8601, UTC)."
                          },
                          "delivered_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Entregado (ISO 8601, UTC)."
                          },
                          "read_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Leído (ISO 8601, UTC)."
                          },
                          "failed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Falló (ISO 8601, UTC)."
                          },
                          "edited_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Editado (ISO 8601, UTC)."
                          },
                          "revoked_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Borrado por el remitente (ISO 8601, UTC)."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Error del envío, en el formato de Meta; `null` = sin error."
                          },
                          "campaign": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string",
                                    "description": "Solo mensajes de esta campaña."
                                  },
                                  "recipient_id": {
                                    "type": "string",
                                    "description": "ID del destinatario de la campaña."
                                  }
                                },
                                "required": [
                                  "id",
                                  "recipient_id"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Campaña que envió el mensaje; `null` fuera de campaña."
                          }
                        },
                        "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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Obtener mensaje",
        "description": "Devuelve un mensaje dentro de la retención de la organización. Los medios aparecen con `id`; el contenido sale en `GET /v1/media/{id}/content`. Permiso: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del mensaje en Messajo (`msg_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El mensaje.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del mensaje en Messajo (`msg_…`).",
                      "examples": [
                        "msg_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del mensaje en Meta; `null` antes de la aceptación."
                    },
                    "direction": {
                      "enum": [
                        "inbound",
                        "outbound"
                      ],
                      "type": "string",
                      "description": "Dirección: `inbound` (recibido) u `outbound` (enviado)."
                    },
                    "source": {
                      "enum": [
                        "customer",
                        "api",
                        "business_app",
                        "history",
                        "campaign"
                      ],
                      "type": "string",
                      "description": "Origen: `customer`, `api`, `business_app`, `history` o `campaign`."
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "Cuándo ocurrió el mensaje (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": "Contenido normalizado (el mismo de los 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: respuesta, reenvío, anuncio de origen; `null` = sin contexto."
                    },
                    "conversation_id": {
                      "type": "string",
                      "description": "ID de la conversación."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del contacto."
                    },
                    "status": {
                      "enum": [
                        "received",
                        "queued",
                        "sent",
                        "delivered",
                        "read",
                        "played",
                        "failed",
                        "deleted"
                      ],
                      "type": "string",
                      "description": "Estado del mensaje."
                    },
                    "sent_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enviado (ISO 8601, UTC)."
                    },
                    "delivered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Entregado (ISO 8601, UTC)."
                    },
                    "read_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Leído (ISO 8601, UTC)."
                    },
                    "failed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Falló (ISO 8601, UTC)."
                    },
                    "edited_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Editado (ISO 8601, UTC)."
                    },
                    "revoked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Borrado por el remitente (ISO 8601, UTC)."
                    },
                    "error": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Error del envío, en el formato de Meta; `null` = sin error."
                    },
                    "campaign": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "description": "Solo mensajes de esta campaña."
                            },
                            "recipient_id": {
                              "type": "string",
                              "description": "ID del destinatario de la campaña."
                            }
                          },
                          "required": [
                            "id",
                            "recipient_id"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Campaña que envió el mensaje; `null` fuera de campaña."
                    }
                  },
                  "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 contactos",
        "description": "Lista los contactos, del visto más recientemente al más antiguo. `identity` es búsqueda exacta (teléfono, BSUID, @usuario, IGSID/PSID); `q` busca por el inicio del nombre. Una clave limitada a conexiones solo ve contactos con conversación en ellas. Permiso: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512,
              "description": "Cursor opaco de la página siguiente: el `next_cursor` de la respuesta anterior, con los mismos filtros. Alterado o de otra ruta → `400 invalid_cursor`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "channel",
            "in": "query",
            "schema": {
              "enum": [
                "whatsapp",
                "instagram",
                "messenger"
              ],
              "type": "string",
              "description": "Canal: `whatsapp`, `instagram` o `messenger`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "identity",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "description": "Identidad exacta: teléfono (solo dígitos), BSUID, @usuario, IGSID o PSID."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "description": "Inicio del nombre del contacto (hasta 64 caracteres)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Contactos vistos desde esta fecha (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de contactos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del contacto."
                          },
                          "channel": {
                            "enum": [
                              "whatsapp",
                              "instagram",
                              "messenger"
                            ],
                            "type": "string",
                            "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                          },
                          "display_name": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre del contacto, cuando se conoce."
                          },
                          "identities": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "kind": {
                                  "type": "string",
                                  "description": "Tipo: `wa_id`, `bsuid`, `username`, `igsid` o `psid`."
                                },
                                "value": {
                                  "type": "string",
                                  "description": "Valor de la identidad."
                                },
                                "scope": {
                                  "type": "string",
                                  "description": "Alcance de la identidad (p. ej. el portafolio del BSUID); vacío = global."
                                }
                              },
                              "required": [
                                "kind",
                                "value",
                                "scope"
                              ]
                            },
                            "description": "Identidades del contacto en el canal."
                          },
                          "first_seen_at": {
                            "type": "string",
                            "description": "Primera vez que apareció el contacto (ISO 8601, UTC)."
                          },
                          "last_seen_at": {
                            "type": "string",
                            "description": "Última vez que apareció el contacto (ISO 8601, UTC)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Fecha de creación (ISO 8601, UTC)."
                          }
                        },
                        "required": [
                          "id",
                          "channel",
                          "display_name",
                          "identities",
                          "first_seen_at",
                          "last_seen_at",
                          "created_at"
                        ]
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Obtener contacto",
        "description": "Devuelve un contacto con sus identidades. Permiso: `read`.",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del contacto."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El contacto.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del contacto."
                    },
                    "channel": {
                      "enum": [
                        "whatsapp",
                        "instagram",
                        "messenger"
                      ],
                      "type": "string",
                      "description": "Canal: `whatsapp`, `instagram` o `messenger`."
                    },
                    "display_name": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre del contacto, cuando se conoce."
                    },
                    "identities": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "description": "Tipo: `wa_id`, `bsuid`, `username`, `igsid` o `psid`."
                          },
                          "value": {
                            "type": "string",
                            "description": "Valor de la identidad."
                          },
                          "scope": {
                            "type": "string",
                            "description": "Alcance de la identidad (p. ej. el portafolio del BSUID); vacío = global."
                          }
                        },
                        "required": [
                          "kind",
                          "value",
                          "scope"
                        ]
                      },
                      "description": "Identidades del contacto en el canal."
                    },
                    "first_seen_at": {
                      "type": "string",
                      "description": "Primera vez que apareció el contacto (ISO 8601, UTC)."
                    },
                    "last_seen_at": {
                      "type": "string",
                      "description": "Última vez que apareció el contacto (ISO 8601, UTC)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (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 campañas",
        "description": "Lista las campañas de la organización, de la más nueva a la más antigua. Una clave limitada a conexiones solo ve sus campañas. Permiso: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de campañas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la campaña (`cmp_…`).",
                            "examples": [
                              "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "name": {
                            "type": "string",
                            "description": "Nombre de la campaña."
                          },
                          "status": {
                            "enum": [
                              "draft",
                              "scheduled",
                              "running",
                              "waiting_limit",
                              "paused",
                              "auto_paused",
                              "completed",
                              "canceled"
                            ],
                            "type": "string",
                            "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                          },
                          "template": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "anyOf": [
                                  {
                                    "type": "string"
                                  },
                                  {
                                    "type": "null"
                                  }
                                ],
                                "description": "ID de la plantilla en Messajo."
                              },
                              "name": {
                                "type": "string",
                                "description": "Nombre de la plantilla."
                              },
                              "language": {
                                "type": "string",
                                "description": "Idioma de la plantilla, p. ej. `es`."
                              },
                              "category": {
                                "type": "string",
                                "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                              }
                            },
                            "required": [
                              "id",
                              "name",
                              "language",
                              "category"
                            ],
                            "description": "Plantilla de la campaña."
                          },
                          "variables": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {},
                            "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                          },
                          "rate_limit_mps": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                          },
                          "effective_rate_mps": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Mensajes por segundo usados de hecho."
                          },
                          "scheduled_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Inicio programado (ISO 8601)."
                          },
                          "started_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                          },
                          "completed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Finalización (ISO 8601, UTC)."
                          },
                          "canceled_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cancelación (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": "Fallos por código de error."
                              }
                            },
                            "required": [
                              "total",
                              "pending",
                              "invalid",
                              "sending",
                              "sent",
                              "delivered",
                              "read",
                              "failed",
                              "unknown",
                              "skipped",
                              "by_error"
                            ],
                            "description": "Destinatarios por estado."
                          },
                          "estimate": {
                            "type": "object",
                            "properties": {
                              "recipients_valid": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Destinatarios que aún faltan por enviar."
                              },
                              "effective_rate_mps": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Mensajes por segundo usados de hecho."
                              },
                              "duration_s": {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Duración estimada en segundos."
                              },
                              "limit": {
                                "type": "object",
                                "properties": {
                                  "tier": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Tope del límite; `null` = ilimitado."
                                  },
                                  "used_24h": {
                                    "type": "integer",
                                    "minimum": -9007199254740991,
                                    "maximum": 9007199254740991,
                                    "description": "Destinatarios contados en las últimas 24 h."
                                  },
                                  "remaining": {
                                    "anyOf": [
                                      {
                                        "type": "integer",
                                        "minimum": -9007199254740991,
                                        "maximum": 9007199254740991
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Cupos restantes; `null` = ilimitado."
                                  }
                                },
                                "required": [
                                  "tier",
                                  "used_24h",
                                  "remaining"
                                ],
                                "description": "Límite de 24 h del portafolio."
                              }
                            },
                            "required": [
                              "recipients_valid",
                              "effective_rate_mps",
                              "duration_s",
                              "limit"
                            ],
                            "description": "Estimación del envío."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Fecha de creación (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Crear campaña",
        "description": "Crea una campaña en `draft` para una conexión de WhatsApp con una plantilla aprobada (`MARKETING` o `UTILITY`). El mapeo en `variables` debe cubrir todos los parámetros de la plantilla. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "description": "Nombre de la campaña."
                  },
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                  },
                  "template_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la plantilla en Messajo."
                  },
                  "template": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Nombre de la plantilla."
                      },
                      "language": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Idioma de la plantilla, p. ej. `es`."
                      }
                    },
                    "required": [
                      "name",
                      "language"
                    ],
                    "description": "Plantilla por nombre e idioma (en lugar de `template_id`)."
                  },
                  "variables": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                  },
                  "rate_limit_mps": {
                    "anyOf": [
                      {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 9007199254740991
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                  }
                },
                "required": [
                  "name",
                  "variables"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "La campaña creada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Obtener campaña",
        "description": "Devuelve la campaña con el conteo por estado (`stats`) y la estimación de envío (`estimate`). Permiso: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La campaña.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Modificar campaña",
        "description": "Plantilla, `variables` y destinatarios solo cambian en `draft`; `name` y `rate_limit_mps` también en `scheduled`, `paused` y `auto_paused`. Si no: `409 campaign_not_editable`. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "description": "Nombre de la campaña."
                  },
                  "template_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la plantilla en Messajo."
                  },
                  "template": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Nombre de la plantilla."
                      },
                      "language": {
                        "type": "string",
                        "minLength": 1,
                        "description": "Idioma de la plantilla, p. ej. `es`."
                      }
                    },
                    "required": [
                      "name",
                      "language"
                    ],
                    "description": "Plantilla por nombre e idioma (en lugar de `template_id`)."
                  },
                  "variables": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                  },
                  "rate_limit_mps": {
                    "anyOf": [
                      {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 9007199254740991
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La campaña modificada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Eliminar campaña",
        "description": "Elimina la campaña y sus destinatarios. Solo en `draft`, `completed` o `canceled`. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmación de la eliminación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `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": "Agregar destinatarios",
        "description": "JSON `{ recipients }` (hasta 10 000 por llamada) se guarda al momento y devuelve la importación completada (`201`). Multipart con `file` (CSV, JSON o NDJSON, hasta 20 MiB) devuelve `202` y se procesa en segundo plano: síguela en `GET /v1/campaigns/{id}/imports/{import_id}`. Solo en `draft`. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`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: teléfono (con código de país), BSUID o `ctc_…` de un contacto."
                        },
                        "variables": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "string",
                            "maxLength": 1024
                          },
                          "description": "Variables del destinatario (columna → valor)."
                        }
                      },
                      "required": [
                        "to"
                      ]
                    },
                    "description": "Destinatarios inline (hasta 10 000)."
                  },
                  "file": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "Archivo CSV, JSON o NDJSON (hasta 20 MiB)."
                  },
                  "to_column": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Columna del CSV con el destino (por defecto `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: teléfono (con código de país), BSUID o `ctc_…` de un contacto."
                        },
                        "variables": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {
                            "type": "string",
                            "maxLength": 1024
                          },
                          "description": "Variables del destinatario (columna → valor)."
                        }
                      },
                      "required": [
                        "to"
                      ]
                    },
                    "description": "Destinatarios inline (hasta 10 000)."
                  },
                  "file": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "Archivo CSV, JSON o NDJSON (hasta 20 MiB)."
                  },
                  "to_column": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Columna del CSV con el destino (por defecto `to`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Lista inline guardada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la importación (`cim_…`)."
                    },
                    "campaign_id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`)."
                    },
                    "source": {
                      "enum": [
                        "inline",
                        "csv",
                        "json",
                        "ndjson"
                      ],
                      "type": "string",
                      "description": "Origen: `inline`, `csv`, `json` o `ndjson`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre del archivo enviado."
                    },
                    "status": {
                      "enum": [
                        "queued",
                        "processing",
                        "completed",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado: `queued`, `processing`, `completed` o `failed`."
                    },
                    "rows_total": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas leídas."
                    },
                    "rows_valid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Destinatarios válidos guardados."
                    },
                    "rows_invalid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas inválidas."
                    },
                    "rows_duplicate": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas 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": "Hasta 100 errores por fila (`row`, `column`, `code`)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (ISO 8601, UTC)."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (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": "Archivo recibido; la importación corre en segundo plano.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la importación (`cim_…`)."
                    },
                    "campaign_id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`)."
                    },
                    "source": {
                      "enum": [
                        "inline",
                        "csv",
                        "json",
                        "ndjson"
                      ],
                      "type": "string",
                      "description": "Origen: `inline`, `csv`, `json` o `ndjson`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre del archivo enviado."
                    },
                    "status": {
                      "enum": [
                        "queued",
                        "processing",
                        "completed",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado: `queued`, `processing`, `completed` o `failed`."
                    },
                    "rows_total": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas leídas."
                    },
                    "rows_valid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Destinatarios válidos guardados."
                    },
                    "rows_invalid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas inválidas."
                    },
                    "rows_duplicate": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas 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": "Hasta 100 errores por fila (`row`, `column`, `code`)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (ISO 8601, UTC)."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (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 destinatarios",
        "description": "Lista los destinatarios de la campaña en orden de envío, con filtro por estado. Permiso: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending",
                "invalid",
                "sending",
                "sent",
                "delivered",
                "read",
                "failed",
                "unknown",
                "skipped"
              ],
              "type": "string",
              "description": "Estado del destinatario: `pending`, `invalid`, `sending`, `sent`, `delivered`, `read`, `failed`, `unknown` o `skipped`."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de destinatarios.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del destinatario (`crc_…`)."
                          },
                          "seq": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Posición en el orden de envío."
                          },
                          "to_kind": {
                            "enum": [
                              "phone",
                              "bsuid"
                            ],
                            "type": "string",
                            "description": "Tipo de destino: `phone` o `bsuid`."
                          },
                          "to": {
                            "type": "string",
                            "description": "Destino: teléfono (con código de país), BSUID o `ctc_…` de un contacto."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Contacto del destinatario, cuando se conoce."
                          },
                          "variables": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {
                              "type": "string"
                            },
                            "description": "Variables del destinatario (columna → valor)."
                          },
                          "status": {
                            "enum": [
                              "pending",
                              "invalid",
                              "sending",
                              "sent",
                              "delivered",
                              "read",
                              "failed",
                              "unknown",
                              "skipped"
                            ],
                            "type": "string",
                            "description": "Estado del destinatario: `pending`, `invalid`, `sending`, `sent`, `delivered`, `read`, `failed`, `unknown` o `skipped`."
                          },
                          "invalid_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Por qué el destinatario es inválido."
                          },
                          "message_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del mensaje enviado (`msg_…`)."
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del mensaje en 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": "Error del envío (`code`, `meta_code`, `message`)."
                          },
                          "sent_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Enviado (ISO 8601, UTC)."
                          },
                          "delivered_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Entregado (ISO 8601, UTC)."
                          },
                          "read_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Leído (ISO 8601, UTC)."
                          },
                          "failed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Falló (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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 importaciones",
        "description": "Lista las importaciones de destinatarios de la campaña, de la más nueva a la más antigua. Permiso: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Una página de importaciones.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la importación (`cim_…`)."
                          },
                          "campaign_id": {
                            "type": "string",
                            "description": "ID de la campaña (`cmp_…`)."
                          },
                          "source": {
                            "enum": [
                              "inline",
                              "csv",
                              "json",
                              "ndjson"
                            ],
                            "type": "string",
                            "description": "Origen: `inline`, `csv`, `json` o `ndjson`."
                          },
                          "filename": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre del archivo enviado."
                          },
                          "status": {
                            "enum": [
                              "queued",
                              "processing",
                              "completed",
                              "failed"
                            ],
                            "type": "string",
                            "description": "Estado: `queued`, `processing`, `completed` o `failed`."
                          },
                          "rows_total": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Filas leídas."
                          },
                          "rows_valid": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Destinatarios válidos guardados."
                          },
                          "rows_invalid": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Filas inválidas."
                          },
                          "rows_duplicate": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Filas 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": "Hasta 100 errores por fila (`row`, `column`, `code`)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Fecha de creación (ISO 8601, UTC)."
                          },
                          "started_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Inicio (ISO 8601, UTC)."
                          },
                          "completed_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Finalización (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Obtener importación",
        "description": "Devuelve una importación con los conteos y hasta 100 errores por fila. Permiso: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "name": "import_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la importación (`cim_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La importación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la importación (`cim_…`)."
                    },
                    "campaign_id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`)."
                    },
                    "source": {
                      "enum": [
                        "inline",
                        "csv",
                        "json",
                        "ndjson"
                      ],
                      "type": "string",
                      "description": "Origen: `inline`, `csv`, `json` o `ndjson`."
                    },
                    "filename": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Nombre del archivo enviado."
                    },
                    "status": {
                      "enum": [
                        "queued",
                        "processing",
                        "completed",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado: `queued`, `processing`, `completed` o `failed`."
                    },
                    "rows_total": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas leídas."
                    },
                    "rows_valid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Destinatarios válidos guardados."
                    },
                    "rows_invalid": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas inválidas."
                    },
                    "rows_duplicate": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Filas 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": "Hasta 100 errores por fila (`row`, `column`, `code`)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (ISO 8601, UTC)."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (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": "Previsualizar campaña",
        "description": "Arma el mensaje de los primeros destinatarios válidos con las variables reemplazadas, sin enviar nada. Permiso: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`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": "Cuántos destinatarios previsualizar (1 a 10, por defecto 5)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Los mensajes armados.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "recipient_id": {
                            "type": "string",
                            "description": "ID del destinatario (`crc_…`)."
                          },
                          "to": {
                            "type": "string",
                            "description": "Destino: teléfono (con código de país), BSUID o `ctc_…` de un contacto."
                          },
                          "components": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            "description": "`components` de la plantilla, tal como van a Meta."
                          },
                          "rendered_body": {
                            "type": "string",
                            "description": "Cuerpo con los parámetros reemplazados."
                          }
                        },
                        "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": "Programar campaña",
        "description": "Programa el inicio entre ahora + 1 min y ahora + 90 días. Exige al menos un destinatario válido y ninguna importación en curso. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "scheduled_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Inicio programado (ISO 8601)."
                  }
                },
                "required": [
                  "scheduled_at"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La campaña programada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Desprogramar campaña",
        "description": "Devuelve la campaña programada a `draft`. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La campaña en borrador.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 campaña",
        "description": "Inicia el envío ahora desde `draft`. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La campaña en envío.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 campaña",
        "description": "Pausa el envío; lo que ya está saliendo termina. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La campaña pausada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Reanudar campaña",
        "description": "Reanuda una campaña pausada (manual o automáticamente), tomando la calidad actual como referencia. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La campaña en envío.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 campaña",
        "description": "Cancela la campaña; los destinatarios aún no enviados pasan a `skipped`. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "La campaña cancelada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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 campaña",
        "description": "Crea un `draft` con la misma plantilla, mapeo y ritmo; `recipients` elige qué destinatarios copiar. Permiso: `send`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "description": "Nombre de la campaña."
                  },
                  "recipients": {
                    "enum": [
                      "none",
                      "all",
                      "failed",
                      "unknown_or_failed"
                    ],
                    "type": "string",
                    "default": "none",
                    "description": "Destinatarios a copiar: `none`, `all`, `failed` o `unknown_or_failed`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "La campaña nueva.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la campaña (`cmp_…`).",
                      "examples": [
                        "cmp_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre de la campaña."
                    },
                    "status": {
                      "enum": [
                        "draft",
                        "scheduled",
                        "running",
                        "waiting_limit",
                        "paused",
                        "auto_paused",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado: `draft`, `scheduled`, `running`, `waiting_limit`, `paused`, `auto_paused`, `completed` o `canceled`."
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp que envía. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "template": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "ID de la plantilla en Messajo."
                        },
                        "name": {
                          "type": "string",
                          "description": "Nombre de la plantilla."
                        },
                        "language": {
                          "type": "string",
                          "description": "Idioma de la plantilla, p. ej. `es`."
                        },
                        "category": {
                          "type": "string",
                          "description": "Categoría de la plantilla: `MARKETING` o `UTILITY`."
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "language",
                        "category"
                      ],
                      "description": "Plantilla de la campaña."
                    },
                    "variables": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Mapeo de las variables de la plantilla: `header`, `body` y `buttons`, cada parámetro con `column` (columna de la lista), `value` (fijo) o `contact: \"display_name\"`."
                    },
                    "rate_limit_mps": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Mensajes por segundo; `null` = automático (80 % del rendimiento del número)."
                    },
                    "effective_rate_mps": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Mensajes por segundo usados de hecho."
                    },
                    "scheduled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio programado (ISO 8601)."
                    },
                    "started_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio (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 de la pausa: `manual` o el motivo de la pausa automática."
                    },
                    "completed_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Finalización (ISO 8601, UTC)."
                    },
                    "canceled_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cancelación (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": "Fallos por código de error."
                        }
                      },
                      "required": [
                        "total",
                        "pending",
                        "invalid",
                        "sending",
                        "sent",
                        "delivered",
                        "read",
                        "failed",
                        "unknown",
                        "skipped",
                        "by_error"
                      ],
                      "description": "Destinatarios por estado."
                    },
                    "estimate": {
                      "type": "object",
                      "properties": {
                        "recipients_valid": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Destinatarios que aún faltan por enviar."
                        },
                        "effective_rate_mps": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Mensajes por segundo usados de hecho."
                        },
                        "duration_s": {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991,
                          "description": "Duración estimada en segundos."
                        },
                        "limit": {
                          "type": "object",
                          "properties": {
                            "tier": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Tope del límite; `null` = ilimitado."
                            },
                            "used_24h": {
                              "type": "integer",
                              "minimum": -9007199254740991,
                              "maximum": 9007199254740991,
                              "description": "Destinatarios contados en las últimas 24 h."
                            },
                            "remaining": {
                              "anyOf": [
                                {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cupos restantes; `null` = ilimitado."
                            }
                          },
                          "required": [
                            "tier",
                            "used_24h",
                            "remaining"
                          ],
                          "description": "Límite de 24 h del portafolio."
                        }
                      },
                      "required": [
                        "recipients_valid",
                        "effective_rate_mps",
                        "duration_s",
                        "limit"
                      ],
                      "description": "Estimación del envío."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Fecha de creación (ISO 8601, UTC)."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio (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": "Descargar informe",
        "description": "CSV con una línea por destinatario: estado, error, ids del mensaje, horarios y variables. Permiso: `read`.",
        "tags": [
          "campaigns"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la campaña (`cmp_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El informe en CSV.",
            "content": {
              "*/*": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "*/*",
                  "description": "Informe 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 llamadas",
        "description": "Registro de llamadas de la organización, más recientes primero, con filtros por conexión, dirección, estado, motivo de fin, contacto y período. La lectura nunca trae el SDP (solo `has_sdp`): llega en los eventos `call.*`. Permiso: `read`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "direction",
            "in": "query",
            "schema": {
              "enum": [
                "user_initiated",
                "business_initiated"
              ],
              "type": "string",
              "description": "`user_initiated` (llamó el usuario) o `business_initiated` (llamó el número)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "offered",
                "pre_accepted",
                "dialing",
                "ringing",
                "accepted",
                "terminating",
                "ended",
                "rejected"
              ],
              "type": "string",
              "description": "Estado de la llamada."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "end_reason",
            "in": "query",
            "schema": {
              "enum": [
                "completed",
                "failed",
                "rejected",
                "missed",
                "canceled",
                "unknown"
              ],
              "type": "string",
              "description": "Motivo del fin, cuando terminó."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "contact_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Contacto de la llamada, cuando se conoce."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Solo llamadas creadas desde esta fecha (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time",
              "description": "Solo llamadas creadas hasta esta fecha (ISO 8601)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de llamadas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la llamada (`cal_…`).",
                            "examples": [
                              "cal_0193a1b2c3d47e8f"
                            ]
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
                          },
                          "contact_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Contacto de la llamada, cuando se conoce."
                          },
                          "conversation_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Conversación de la llamada, si la hay."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID de la llamada en Meta (`wacid.…`)."
                          },
                          "direction": {
                            "enum": [
                              "user_initiated",
                              "business_initiated"
                            ],
                            "type": "string",
                            "description": "`user_initiated` (llamó el usuario) o `business_initiated` (llamó el número)."
                          },
                          "status": {
                            "enum": [
                              "offered",
                              "pre_accepted",
                              "dialing",
                              "ringing",
                              "accepted",
                              "terminating",
                              "ended",
                              "rejected"
                            ],
                            "type": "string",
                            "description": "Estado de la llamada."
                          },
                          "end_reason": {
                            "anyOf": [
                              {
                                "enum": [
                                  "completed",
                                  "failed",
                                  "rejected",
                                  "missed",
                                  "canceled",
                                  "unknown"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo del fin, cuando terminó."
                          },
                          "has_sdp": {
                            "type": "boolean",
                            "description": "`true` mientras el SDP está guardado (se borra 1 h después del fin)."
                          },
                          "biz_opaque_callback_data": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                          },
                          "errors": {
                            "anyOf": [
                              {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "propertyNames": {
                                    "type": "string"
                                  },
                                  "additionalProperties": {}
                                }
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Errores que Meta informó en la llamada."
                          },
                          "offered_at": {
                            "type": "string",
                            "description": "Cuándo empezó a sonar."
                          },
                          "answered_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo se atendió."
                          },
                          "start_time": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Inicio de la conversación, según Meta."
                          },
                          "end_time": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Fin de la llamada."
                          },
                          "duration_s": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Duración en segundos."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó la fila."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio."
                          }
                        },
                        "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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Llamar al usuario",
        "description": "Inicia una llamada al usuario con la oferta SDP. Requiere el permiso de llamada del usuario (`call_permission_required` sin él) y la Calling API activada en el número. Número en coexistencia → `422 calling_not_supported_in_coex`. Permiso: `send`.",
        "tags": [
          "calls"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
                  },
                  "to": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Teléfono (solo dígitos, con código de país) o BSUID del usuario."
                  },
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP en texto (hasta 64 KiB, empieza con `v=0`). Obligatorio en `pre-accept` y `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                  }
                },
                "required": [
                  "to",
                  "sdp"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "La llamada creada, en `dialing`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la llamada (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contacto de la llamada, cuando se conoce."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversación de la llamada, si la hay."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la llamada en Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (llamó el usuario) o `business_initiated` (llamó el número)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado de la llamada."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del fin, cuando terminó."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` mientras el SDP está guardado (se borra 1 h después del fin)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Errores que Meta informó en la llamada."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Cuándo empezó a sonar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se atendió."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio de la conversación, según Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fin de la llamada."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración en segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la fila."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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 llamada",
        "description": "Una llamada del registro, sin el SDP. Permiso: `read`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la llamada (`cal_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La llamada.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la llamada (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contacto de la llamada, cuando se conoce."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversación de la llamada, si la hay."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la llamada en Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (llamó el usuario) o `business_initiated` (llamó el número)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado de la llamada."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del fin, cuando terminó."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` mientras el SDP está guardado (se borra 1 h después del fin)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Errores que Meta informó en la llamada."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Cuándo empezó a sonar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se atendió."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio de la conversación, según Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fin de la llamada."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración en segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la fila."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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": "Preaceptar llamada",
        "description": "Envía el SDP de respuesta antes de atender, para que el audio conecte más rápido. El `accept` siguiente debe usar el mismo SDP. Solo con la llamada `offered`. Permiso: `send`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la llamada (`cal_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP en texto (hasta 64 KiB, empieza con `v=0`). Obligatorio en `pre-accept` y `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La llamada en `pre_accepted`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la llamada (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contacto de la llamada, cuando se conoce."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversación de la llamada, si la hay."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la llamada en Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (llamó el usuario) o `business_initiated` (llamó el número)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado de la llamada."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del fin, cuando terminó."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` mientras el SDP está guardado (se borra 1 h después del fin)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Errores que Meta informó en la llamada."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Cuándo empezó a sonar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se atendió."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio de la conversación, según Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fin de la llamada."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración en segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la fila."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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 llamada",
        "description": "Atiende la llamada con el SDP de respuesta (el mismo del `pre-accept`, si lo hubo; si no, `409 call_sdp_mismatch`). El audio va entre Meta y tu cliente WebRTC/SIP, nunca por Messajo. Permiso: `send`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la llamada (`cal_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP en texto (hasta 64 KiB, empieza con `v=0`). Obligatorio en `pre-accept` y `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La llamada en `accepted`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la llamada (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contacto de la llamada, cuando se conoce."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversación de la llamada, si la hay."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la llamada en Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (llamó el usuario) o `business_initiated` (llamó el número)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado de la llamada."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del fin, cuando terminó."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` mientras el SDP está guardado (se borra 1 h después del fin)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Errores que Meta informó en la llamada."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Cuándo empezó a sonar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se atendió."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio de la conversación, según Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fin de la llamada."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración en segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la fila."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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": "Rechazar llamada",
        "description": "Rechaza una llamada entrante aún no atendida. Permiso: `send`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la llamada (`cal_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP en texto (hasta 64 KiB, empieza con `v=0`). Obligatorio en `pre-accept` y `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La llamada en `rejected`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la llamada (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contacto de la llamada, cuando se conoce."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversación de la llamada, si la hay."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la llamada en Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (llamó el usuario) o `business_initiated` (llamó el número)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado de la llamada."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del fin, cuando terminó."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` mientras el SDP está guardado (se borra 1 h después del fin)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Errores que Meta informó en la llamada."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Cuándo empezó a sonar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se atendió."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio de la conversación, según Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fin de la llamada."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración en segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la fila."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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": "Terminar llamada",
        "description": "Cuelga una llamada atendida o en curso. El `call.ended` llega por el webhook de Meta, con la duración. Permiso: `send`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la llamada (`cal_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sdp": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "SDP en texto (hasta 64 KiB, empieza con `v=0`). Obligatorio en `pre-accept` y `accept`."
                  },
                  "biz_opaque_callback_data": {
                    "type": "string",
                    "maxLength": 512,
                    "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La llamada en `terminating`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID de la llamada (`cal_…`).",
                      "examples": [
                        "cal_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "contact_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Contacto de la llamada, cuando se conoce."
                    },
                    "conversation_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Conversación de la llamada, si la hay."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID de la llamada en Meta (`wacid.…`)."
                    },
                    "direction": {
                      "enum": [
                        "user_initiated",
                        "business_initiated"
                      ],
                      "type": "string",
                      "description": "`user_initiated` (llamó el usuario) o `business_initiated` (llamó el número)."
                    },
                    "status": {
                      "enum": [
                        "offered",
                        "pre_accepted",
                        "dialing",
                        "ringing",
                        "accepted",
                        "terminating",
                        "ended",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Estado de la llamada."
                    },
                    "end_reason": {
                      "anyOf": [
                        {
                          "enum": [
                            "completed",
                            "failed",
                            "rejected",
                            "missed",
                            "canceled",
                            "unknown"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Motivo del fin, cuando terminó."
                    },
                    "has_sdp": {
                      "type": "boolean",
                      "description": "`true` mientras el SDP está guardado (se borra 1 h después del fin)."
                    },
                    "biz_opaque_callback_data": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto tuyo que Meta devuelve en los webhooks de esta llamada."
                    },
                    "errors": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {}
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Errores que Meta informó en la llamada."
                    },
                    "offered_at": {
                      "type": "string",
                      "description": "Cuándo empezó a sonar."
                    },
                    "answered_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se atendió."
                    },
                    "start_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Inicio de la conversación, según Meta."
                    },
                    "end_time": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Fin de la llamada."
                    },
                    "duration_s": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Duración en segundos."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó la fila."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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 permiso de llamada",
        "description": "Pregunta a Meta si el número puede llamar al usuario ahora y qué acciones están permitidas, con los límites. Actualiza la caché local. Permiso: `read`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Teléfono (solo dígitos, con código de país) o BSUID del usuario."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Estado del permiso y acciones posibles.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "enum": [
                        "no_permission",
                        "temporary",
                        "permanent",
                        "rejected"
                      ],
                      "type": "string",
                      "description": "Permiso del usuario: `no_permission`, `temporary`, `permanent` o `rejected`."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo vence el permiso temporal."
                    },
                    "actions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "action_name": {
                            "type": "string",
                            "description": "Nombre de la acción en Meta (p. ej., `start_call`, `send_call_permission_request`)."
                          },
                          "can_perform_action": {
                            "type": "boolean",
                            "description": "Si la acción se puede hacer ahora."
                          },
                          "limits": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            "description": "Límites de Meta para la acción, tal como llegaron."
                          }
                        },
                        "required": [
                          "action_name",
                          "can_perform_action",
                          "limits"
                        ]
                      },
                      "description": "Acciones sobre el permiso y si se pueden hacer ahora."
                    }
                  },
                  "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 configuración de llamadas",
        "description": "Bloque `calling` de la configuración del número: estado, ícono, devolución, horario de atención y SIP. `include_sip_credentials=true` devuelve la contraseña SIP una sola vez y exige `admin`; nunca se guarda. Permiso: `read`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
            }
          },
          {
            "name": "include_sip_credentials",
            "in": "query",
            "schema": {
              "enum": [
                "true",
                "false"
              ],
              "type": "string",
              "description": "`true` devuelve la contraseña SIP (exige `admin`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "La configuración de llamadas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "enum": [
                        "ENABLED",
                        "DISABLED"
                      ],
                      "type": "string",
                      "description": "Calling API activada (`ENABLED`) o desactivada (`DISABLED`) en el número."
                    },
                    "call_icon_visibility": {
                      "enum": [
                        "DEFAULT",
                        "DISABLE_ALL"
                      ],
                      "type": "string",
                      "description": "Mostrar (`DEFAULT`) u ocultar (`DISABLE_ALL`) el ícono de llamada en el WhatsApp del usuario."
                    },
                    "callback_permission_status": {
                      "enum": [
                        "ENABLED",
                        "DISABLED"
                      ],
                      "type": "string",
                      "description": "Pedir permiso de devolución automáticamente cuando el usuario llama."
                    },
                    "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": "Horario de atención (semana y feriados); `null` = sin horario."
                    },
                    "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": "Contraseña SIP del servidor; solo con `include_sip_credentials=true`, una vez."
                                  }
                                },
                                "required": [
                                  "hostname",
                                  "port"
                                ]
                              }
                            }
                          },
                          "required": [
                            "status",
                            "servers"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Configuración SIP; `null` = sin 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": "Cambiar configuración de llamadas",
        "description": "Actualización parcial del bloque `calling` (activar la Calling API, horario, ícono, devolución y servidores SIP). El hostname SIP no puede ser una IP privada. Queda en la auditoría. Permiso: `admin`.",
        "tags": [
          "calls"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión (número) de la llamada. Opcional con una clave de conexión (usa la conexión de la clave)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "enum": [
                      "ENABLED",
                      "DISABLED"
                    ],
                    "type": "string",
                    "description": "Calling API activada (`ENABLED`) o desactivada (`DISABLED`) en el número."
                  },
                  "call_icon_visibility": {
                    "enum": [
                      "DEFAULT",
                      "DISABLE_ALL"
                    ],
                    "type": "string",
                    "description": "Mostrar (`DEFAULT`) u ocultar (`DISABLE_ALL`) el ícono de llamada en el WhatsApp del usuario."
                  },
                  "callback_permission_status": {
                    "enum": [
                      "ENABLED",
                      "DISABLED"
                    ],
                    "type": "string",
                    "description": "Pedir permiso de devolución automáticamente cuando el usuario llama."
                  },
                  "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": "Horario de atención (semana y feriados); `null` = sin horario."
                  },
                  "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": "Configuración SIP; `null` = sin SIP."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La configuración después del cambio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "enum": [
                        "ENABLED",
                        "DISABLED"
                      ],
                      "type": "string",
                      "description": "Calling API activada (`ENABLED`) o desactivada (`DISABLED`) en el número."
                    },
                    "call_icon_visibility": {
                      "enum": [
                        "DEFAULT",
                        "DISABLE_ALL"
                      ],
                      "type": "string",
                      "description": "Mostrar (`DEFAULT`) u ocultar (`DISABLE_ALL`) el ícono de llamada en el WhatsApp del usuario."
                    },
                    "callback_permission_status": {
                      "enum": [
                        "ENABLED",
                        "DISABLED"
                      ],
                      "type": "string",
                      "description": "Pedir permiso de devolución automáticamente cuando el usuario llama."
                    },
                    "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": "Horario de atención (semana y feriados); `null` = sin horario."
                    },
                    "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": "Contraseña SIP del servidor; solo con `include_sip_credentials=true`, una vez."
                                  }
                                },
                                "required": [
                                  "hostname",
                                  "port"
                                ]
                              }
                            }
                          },
                          "required": [
                            "status",
                            "servers"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Configuración SIP; `null` = sin 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": "Crear grupo",
        "description": "Crea un grupo en el número. Meta confirma por webhook: el grupo nace `creating` y pasa a `active` (evento `group.created`) o `failed` (`group.create_failed`). Número en coexistencia → `422 group_not_supported`. Permiso: `send`.",
        "tags": [
          "groups"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión (número) dueña del grupo. Opcional con una clave de conexión (usa la conexión de la clave)."
                  },
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Asunto del grupo (hasta 128 caracteres)."
                  },
                  "description": {
                    "type": "string",
                    "description": "Descripción del grupo (hasta 2048 caracteres)."
                  },
                  "join_approval_mode": {
                    "enum": [
                      "auto_approve",
                      "approval_required"
                    ],
                    "type": "string",
                    "description": "`auto_approve` (entra directo por el enlace) o `approval_required` (solicitud de ingreso)."
                  }
                },
                "required": [
                  "subject"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El grupo, en `creating`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo.",
                      "examples": [
                        "grp_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) dueña del grupo. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del grupo en Meta; `null` hasta la confirmación."
                    },
                    "subject": {
                      "type": "string",
                      "description": "Asunto del grupo (hasta 128 caracteres)."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción del grupo (hasta 2048 caracteres)."
                    },
                    "join_approval_mode": {
                      "enum": [
                        "auto_approve",
                        "approval_required"
                      ],
                      "type": "string",
                      "description": "`auto_approve` (entra directo por el enlace) o `approval_required` (solicitud de ingreso)."
                    },
                    "status": {
                      "enum": [
                        "creating",
                        "active",
                        "suspended",
                        "deleting",
                        "deleted",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado del 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": "Teléfono del participante en WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID del participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre de usuario del participante, si lo hay."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo entró (o pidió entrar)."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at"
                        ]
                      },
                      "description": "Participantes (hasta 8)."
                    },
                    "pending_join_requests": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Solicitudes de ingreso pendientes."
                    },
                    "failure": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Error de Meta cuando la creación falló."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó el grupo."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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 de la organización, más recientes primero. Permiso: `read`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión (número) dueña del grupo. Opcional con una clave de conexión (usa la conexión de la clave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "creating",
                "active",
                "suspended",
                "deleting",
                "deleted",
                "failed"
              ],
              "type": "string",
              "description": "Estado del 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 del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo.",
                            "examples": [
                              "grp_0193a1b2c3d47e8f"
                            ]
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID de la conexión (número) dueña del grupo. Opcional con una clave de conexión (usa la conexión de la clave)."
                          },
                          "external_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del grupo en Meta; `null` hasta la confirmación."
                          },
                          "subject": {
                            "type": "string",
                            "description": "Asunto del grupo (hasta 128 caracteres)."
                          },
                          "description": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Descripción del grupo (hasta 2048 caracteres)."
                          },
                          "join_approval_mode": {
                            "enum": [
                              "auto_approve",
                              "approval_required"
                            ],
                            "type": "string",
                            "description": "`auto_approve` (entra directo por el enlace) o `approval_required` (solicitud de ingreso)."
                          },
                          "status": {
                            "enum": [
                              "creating",
                              "active",
                              "suspended",
                              "deleting",
                              "deleted",
                              "failed"
                            ],
                            "type": "string",
                            "description": "Estado del 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": "Teléfono del participante en WhatsApp."
                                },
                                "user_id": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "BSUID del participante."
                                },
                                "username": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "Nombre de usuario del participante, si lo hay."
                                },
                                "joined_at": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "Cuándo entró (o pidió entrar)."
                                }
                              },
                              "required": [
                                "wa_id",
                                "user_id",
                                "username",
                                "joined_at"
                              ]
                            },
                            "description": "Participantes (hasta 8)."
                          },
                          "pending_join_requests": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Solicitudes de ingreso pendientes."
                          },
                          "failure": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Error de Meta cuando la creación falló."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó el grupo."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio."
                          }
                        },
                        "required": [
                          "id",
                          "connection_id",
                          "external_id",
                          "subject",
                          "description",
                          "join_approval_mode",
                          "status",
                          "participant_count",
                          "participants",
                          "pending_join_requests",
                          "failure",
                          "created_at",
                          "updated_at"
                        ]
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Un grupo con asunto, descripción, participantes y solicitudes pendientes. Permiso: `read`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El grupo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo.",
                      "examples": [
                        "grp_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) dueña del grupo. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del grupo en Meta; `null` hasta la confirmación."
                    },
                    "subject": {
                      "type": "string",
                      "description": "Asunto del grupo (hasta 128 caracteres)."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción del grupo (hasta 2048 caracteres)."
                    },
                    "join_approval_mode": {
                      "enum": [
                        "auto_approve",
                        "approval_required"
                      ],
                      "type": "string",
                      "description": "`auto_approve` (entra directo por el enlace) o `approval_required` (solicitud de ingreso)."
                    },
                    "status": {
                      "enum": [
                        "creating",
                        "active",
                        "suspended",
                        "deleting",
                        "deleted",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado del 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": "Teléfono del participante en WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID del participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre de usuario del participante, si lo hay."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo entró (o pidió entrar)."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at"
                        ]
                      },
                      "description": "Participantes (hasta 8)."
                    },
                    "pending_join_requests": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Solicitudes de ingreso pendientes."
                    },
                    "failure": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Error de Meta cuando la creación falló."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó el grupo."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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": "Cambiar grupo",
        "description": "Cambia asunto, descripción o foto (multipart, campo `picture`: JPEG cuadrado de al menos 192 px, hasta 5 MiB). Solo con el grupo `active`. Permiso: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Asunto del grupo (hasta 128 caracteres)."
                  },
                  "description": {
                    "type": "string",
                    "description": "Descripción del grupo (hasta 2048 caracteres)."
                  },
                  "picture": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "Foto del grupo (JPEG cuadrado, ≥ 192 px, ≤ 5 MiB)."
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Asunto del grupo (hasta 128 caracteres)."
                  },
                  "description": {
                    "type": "string",
                    "description": "Descripción del grupo (hasta 2048 caracteres)."
                  },
                  "picture": {
                    "type": "string",
                    "contentMediaType": "*/*",
                    "description": "Foto del grupo (JPEG cuadrado, ≥ 192 px, ≤ 5 MiB)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El grupo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo.",
                      "examples": [
                        "grp_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) dueña del grupo. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del grupo en Meta; `null` hasta la confirmación."
                    },
                    "subject": {
                      "type": "string",
                      "description": "Asunto del grupo (hasta 128 caracteres)."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción del grupo (hasta 2048 caracteres)."
                    },
                    "join_approval_mode": {
                      "enum": [
                        "auto_approve",
                        "approval_required"
                      ],
                      "type": "string",
                      "description": "`auto_approve` (entra directo por el enlace) o `approval_required` (solicitud de ingreso)."
                    },
                    "status": {
                      "enum": [
                        "creating",
                        "active",
                        "suspended",
                        "deleting",
                        "deleted",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado del 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": "Teléfono del participante en WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID del participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre de usuario del participante, si lo hay."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo entró (o pidió entrar)."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at"
                        ]
                      },
                      "description": "Participantes (hasta 8)."
                    },
                    "pending_join_requests": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Solicitudes de ingreso pendientes."
                    },
                    "failure": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Error de Meta cuando la creación falló."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó el grupo."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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": "Borrar grupo",
        "description": "Borra el grupo en Meta y quita a todos los participantes. Queda en la auditoría. Permiso: `admin`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El grupo, en `deleted`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo.",
                      "examples": [
                        "grp_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión (número) dueña del grupo. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "external_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del grupo en Meta; `null` hasta la confirmación."
                    },
                    "subject": {
                      "type": "string",
                      "description": "Asunto del grupo (hasta 128 caracteres)."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción del grupo (hasta 2048 caracteres)."
                    },
                    "join_approval_mode": {
                      "enum": [
                        "auto_approve",
                        "approval_required"
                      ],
                      "type": "string",
                      "description": "`auto_approve` (entra directo por el enlace) o `approval_required` (solicitud de ingreso)."
                    },
                    "status": {
                      "enum": [
                        "creating",
                        "active",
                        "suspended",
                        "deleting",
                        "deleted",
                        "failed"
                      ],
                      "type": "string",
                      "description": "Estado del 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": "Teléfono del participante en WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID del participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre de usuario del participante, si lo hay."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo entró (o pidió entrar)."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at"
                        ]
                      },
                      "description": "Participantes (hasta 8)."
                    },
                    "pending_join_requests": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Solicitudes de ingreso pendientes."
                    },
                    "failure": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Error de Meta cuando la creación falló."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó el grupo."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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 enlace de invitación",
        "description": "Enlace de invitación actual del grupo. Permiso: `read`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El enlace de invitación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invite_link": {
                      "type": "string",
                      "description": "Enlace de invitación del 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": "Cambiar enlace de invitación",
        "description": "Genera un enlace nuevo; el anterior deja de funcionar. Permiso: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "El enlace nuevo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invite_link": {
                      "type": "string",
                      "description": "Enlace de invitación del 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": "Quitar participantes",
        "description": "Quita hasta 8 participantes por llamada, por `wa_id` o `user_id`. Queda en la auditoría. Permiso: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al 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": "Teléfono del participante en WhatsApp."
                            }
                          },
                          "required": [
                            "wa_id"
                          ]
                        },
                        {
                          "type": "object",
                          "properties": {
                            "user_id": {
                              "type": "string",
                              "minLength": 1,
                              "description": "BSUID del participante."
                            }
                          },
                          "required": [
                            "user_id"
                          ]
                        }
                      ]
                    },
                    "description": "Participantes a quitar: `{ wa_id }` o `{ user_id }` (hasta 8)."
                  }
                },
                "required": [
                  "participants"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cuántos se quitaron.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo."
                    },
                    "removed": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Cuántos participantes se quitaron."
                    }
                  },
                  "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 solicitudes de ingreso",
        "description": "Solicitudes pendientes de quien quiere entrar al grupo (grupos con aprobación). Permiso: `read`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al grupo."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de solicitudes.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "wa_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Teléfono del participante en WhatsApp."
                          },
                          "user_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "BSUID del participante."
                          },
                          "username": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre de usuario del participante, si lo hay."
                          },
                          "joined_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo entró (o pidió entrar)."
                          },
                          "id": {
                            "type": "string",
                            "description": "ID de la solicitud de ingreso."
                          }
                        },
                        "required": [
                          "wa_id",
                          "user_id",
                          "username",
                          "joined_at",
                          "id"
                        ]
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Aprobar solicitudes de ingreso",
        "description": "Aprueba solicitudes; Meta decide cada una y las que no funcionaron vuelven en `failed`. Permiso: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al 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 de las solicitudes de ingreso."
                  }
                },
                "required": [
                  "join_request_ids"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Solicitudes aprobadas y las que fallaron.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "approved": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Solicitudes aprobadas."
                    },
                    "failed": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la solicitud de ingreso."
                          },
                          "reason": {
                            "type": "string",
                            "description": "Motivo de la falla."
                          }
                        },
                        "required": [
                          "id",
                          "reason"
                        ]
                      },
                      "description": "Solicitudes que Meta no aceptó, con el 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": "Rechazar solicitudes de ingreso",
        "description": "Rechaza solicitudes; las que no funcionaron vuelven en `failed`. Permiso: `send`.",
        "tags": [
          "groups"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del grupo (`grp_…`); úsalo en `to` del `POST /messages` para escribir al 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 de las solicitudes de ingreso."
                  }
                },
                "required": [
                  "join_request_ids"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Solicitudes rechazadas y las que fallaron.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "rejected": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Solicitudes rechazadas."
                    },
                    "failed": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la solicitud de ingreso."
                          },
                          "reason": {
                            "type": "string",
                            "description": "Motivo de la falla."
                          }
                        },
                        "required": [
                          "id",
                          "reason"
                        ]
                      },
                      "description": "Solicitudes que Meta no aceptó, con el 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 de las cuentas de mensajería (WABA) de la organización, más recientes primero, con filtro por conexión y estado. Una clave limitada a conexiones necesita `connection_id`. Permiso: `read`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "DRAFT",
                "PUBLISHED",
                "DEPRECATED",
                "BLOCKED",
                "THROTTLED"
              ],
              "type": "string",
              "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `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 del Flow (`flw_…`).",
                            "examples": [
                              "flw_0193a1b2c3d47e8f"
                            ]
                          },
                          "connection_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                          },
                          "messaging_account_id": {
                            "type": "string",
                            "description": "ID de la cuenta de mensajería (WABA) en Meta."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID del Flow en Meta."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nombre del Flow (único en la cuenta)."
                          },
                          "categories": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                          },
                          "status": {
                            "enum": [
                              "DRAFT",
                              "PUBLISHED",
                              "DEPRECATED",
                              "BLOCKED",
                              "THROTTLED"
                            ],
                            "type": "string",
                            "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                          },
                          "json_version": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "`version` del JSON del Flow."
                          },
                          "data_api_version": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                          },
                          "endpoint_mode": {
                            "enum": [
                              "none",
                              "messajo"
                            ],
                            "type": "string",
                            "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                          },
                          "handler": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "url_preview": {
                                    "type": "string",
                                    "description": "Origen de la URL del handler."
                                  },
                                  "secret_last4": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "4 últimos caracteres del secreto del handler."
                                  }
                                },
                                "required": [
                                  "url_preview",
                                  "secret_last4"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Handler del cliente, sin URL completa ni encabezados."
                          },
                          "health_status": {
                            "anyOf": [
                              {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                          },
                          "preview": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "url": {
                                    "type": "string",
                                    "description": "Enlace de vista previa de Meta."
                                  },
                                  "expires_at": {
                                    "anyOf": [
                                      {
                                        "type": "string"
                                      },
                                      {
                                        "type": "null"
                                      }
                                    ],
                                    "description": "Cuándo vence el enlace de vista previa."
                                  }
                                },
                                "required": [
                                  "url",
                                  "expires_at"
                                ]
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última vista previa generada."
                          },
                          "last_synced_at": {
                            "type": "string",
                            "description": "Última lectura en Meta."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio."
                          }
                        },
                        "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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Crear Flow",
        "description": "Crea el Flow en Meta en `DRAFT`. Con `endpoint`, activa el endpoint de data exchange de Messajo: Meta llama a `/meta/flows/{id}`, Messajo lo descifra y reenvía la solicitud firmada a tu handler. El `handler_secret` (`Messajo-Signature`) aparece solo en esta respuesta. Con `flow_json`, también sube el JSON; los errores de Meta vuelven en `validation_errors`. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nombre del Flow (único en la cuenta)."
                  },
                  "categories": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "enum": [
                        "SIGN_UP",
                        "SIGN_IN",
                        "APPOINTMENT_BOOKING",
                        "LEAD_GENERATION",
                        "CONTACT_US",
                        "CUSTOMER_SUPPORT",
                        "SURVEY",
                        "OTHER"
                      ],
                      "type": "string"
                    },
                    "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                  },
                  "flow_json": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {},
                    "description": "El `flow.json` (objeto con `version` y `screens`)."
                  },
                  "endpoint": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "minLength": 1,
                        "description": "URL del handler (`https` pública)."
                      },
                      "headers": {
                        "type": "array",
                        "maxItems": 20,
                        "items": {
                          "type": "object",
                          "properties": {
                            "name": {
                              "type": "string",
                              "minLength": 1,
                              "description": "Nombre del encabezado."
                            },
                            "value": {
                              "type": "string",
                              "description": "Valor del encabezado."
                            }
                          },
                          "required": [
                            "name",
                            "value"
                          ]
                        },
                        "description": "Encabezados extra enviados al handler (hasta 20)."
                      }
                    },
                    "required": [
                      "url"
                    ],
                    "description": "Handler del cliente: activa el endpoint de data exchange de Messajo."
                  }
                },
                "required": [
                  "name",
                  "categories"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El Flow creado, con el secreto del handler una vez.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    },
                    "handler_secret": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Secreto del handler (`Messajo-Signature`): aparece solo cuando se genera."
                    }
                  },
                  "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": "Un Flow, sin la URL completa ni los encabezados del handler (solo el origen y los 4 últimos caracteres del secreto). Permiso: `read`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El Flow.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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": "Modificar Flow",
        "description": "Cambia el nombre, las categorías o el handler (`endpoint`; `null` desactiva el endpoint de Messajo). `handler_secret` solo viene cuando se generó un secreto nuevo. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nombre del Flow (único en la cuenta)."
                  },
                  "categories": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "enum": [
                        "SIGN_UP",
                        "SIGN_IN",
                        "APPOINTMENT_BOOKING",
                        "LEAD_GENERATION",
                        "CONTACT_US",
                        "CUSTOMER_SUPPORT",
                        "SURVEY",
                        "OTHER"
                      ],
                      "type": "string"
                    },
                    "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                  },
                  "endpoint": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "url": {
                            "type": "string",
                            "minLength": 1,
                            "description": "URL del handler (`https` pública)."
                          },
                          "headers": {
                            "type": "array",
                            "maxItems": 20,
                            "items": {
                              "type": "object",
                              "properties": {
                                "name": {
                                  "type": "string",
                                  "minLength": 1,
                                  "description": "Nombre del encabezado."
                                },
                                "value": {
                                  "type": "string",
                                  "description": "Valor del encabezado."
                                }
                              },
                              "required": [
                                "name",
                                "value"
                              ]
                            },
                            "description": "Encabezados extra enviados al handler (hasta 20)."
                          }
                        },
                        "required": [
                          "url"
                        ],
                        "description": "Handler del cliente: activa el endpoint de data exchange de Messajo."
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El Flow modificado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    },
                    "handler_secret": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Secreto del handler (`Messajo-Signature`): aparece solo cuando se genera."
                    }
                  },
                  "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": "Eliminar Flow",
        "description": "Elimina un Flow en `DRAFT` (Meta no elimina los publicados: usa `deprecate`). Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `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 del Flow",
        "description": "El cuerpo es el `flow.json` crudo (hasta 10 MiB). Solo en `DRAFT` (si no, `409 flow_not_editable`; publicado → `clone`). Los errores de Meta vuelven como `422 flow_invalid_json` con línea y columna en `details`. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {},
                "description": "El `flow.json` (objeto con `version` y `screens`)."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El Flow con el JSON nuevo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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 el Flow. Con el endpoint de Messajo, exige handler y la clave de la cuenta enviada a un número activo (`409 flow_key_not_uploaded`); Meta hace ping al endpoint. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "El Flow publicado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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": "Deja de aceptar envíos de un Flow publicado. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "El Flow deprecado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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": "Crea un `DRAFT` con el mismo JSON y handler, y un secreto nuevo (aparece solo en esta respuesta). Así se edita un Flow publicado. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nombre del Flow (único en la cuenta)."
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El clon, con el secreto del handler una vez.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    },
                    "handler_secret": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Secreto del handler (`Messajo-Signature`): aparece solo cuando se genera."
                    }
                  },
                  "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": "Previsualizar Flow",
        "description": "Enlace de vista previa de Meta, con vencimiento. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Enlace y vencimiento.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "preview_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Enlace de vista previa de Meta."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo vence el enlace de vista previa."
                    }
                  },
                  "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": "Cambiar secreto del handler",
        "description": "Genera un secreto nuevo para firmar las solicitudes al handler (aparece solo en esta respuesta); el anterior deja de valer al instante. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "El Flow, con el secreto nuevo una vez.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    },
                    "handler_secret": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Secreto del handler (`Messajo-Signature`): aparece solo cuando se genera."
                    }
                  },
                  "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": "Vuelve a leer de Meta los Flows de la cuenta (WABA) del Flow: estado y errores de validación. Permiso: `templates`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "El Flow actualizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del Flow (`flw_…`).",
                      "examples": [
                        "flw_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "ID de la cuenta de mensajería (WABA) en Meta."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del Flow en Meta."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre del Flow (único en la cuenta)."
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Categorías de Meta (`SIGN_UP`, `APPOINTMENT_BOOKING`, `LEAD_GENERATION`…)."
                    },
                    "status": {
                      "enum": [
                        "DRAFT",
                        "PUBLISHED",
                        "DEPRECATED",
                        "BLOCKED",
                        "THROTTLED"
                      ],
                      "type": "string",
                      "description": "`DRAFT`, `PUBLISHED`, `DEPRECATED`, `BLOCKED` o `THROTTLED`."
                    },
                    "json_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`version` del JSON del Flow."
                    },
                    "data_api_version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`data_api_version` del JSON (Flows con 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": "Errores de validación de Meta, con línea y columna."
                    },
                    "endpoint_mode": {
                      "enum": [
                        "none",
                        "messajo"
                      ],
                      "type": "string",
                      "description": "`none` (sin endpoint) o `messajo` (endpoint de data exchange de Messajo)."
                    },
                    "handler": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url_preview": {
                              "type": "string",
                              "description": "Origen de la URL del handler."
                            },
                            "secret_last4": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "4 últimos caracteres del secreto del handler."
                            }
                          },
                          "required": [
                            "url_preview",
                            "secret_last4"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Handler del cliente, sin URL completa ni encabezados."
                    },
                    "health_status": {
                      "anyOf": [
                        {
                          "type": "object",
                          "propertyNames": {
                            "type": "string"
                          },
                          "additionalProperties": {}
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Salud del endpoint según Meta (y alertas del webhook `flows`)."
                    },
                    "preview": {
                      "anyOf": [
                        {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "description": "Enlace de vista previa de Meta."
                            },
                            "expires_at": {
                              "anyOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Cuándo vence el enlace de vista previa."
                            }
                          },
                          "required": [
                            "url",
                            "expires_at"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Última vista previa generada."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en Meta."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Cuándo se creó."
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "Último cambio."
                    }
                  },
                  "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 intercambios del endpoint",
        "description": "Llamadas de Meta al endpoint de data exchange en los últimos 7 días, más recientes primero: acción, pantalla, resultado y tiempos. Nunca trae `data` ni el `flow_token`. Permiso: `read`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID del Flow (`flw_…`)."
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Página de intercambios.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del intercambio (`fex_…`)."
                          },
                          "action": {
                            "enum": [
                              "ping",
                              "INIT",
                              "BACK",
                              "data_exchange",
                              "error_notification"
                            ],
                            "type": "string",
                            "description": "`ping`, `INIT`, `BACK`, `data_exchange` o `error_notification`."
                          },
                          "screen": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Pantalla del Flow, cuando la hay."
                          },
                          "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` o `flow_not_found`."
                          },
                          "handler_status": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Estado HTTP del handler."
                          },
                          "duration_ms": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Tiempo total del intercambio (ms)."
                          },
                          "handler_duration_ms": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Tiempo del handler (ms)."
                          },
                          "request_bytes": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Tamaño de la solicitud de Meta."
                          },
                          "response_bytes": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Tamaño de la respuesta."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo del fallo, sin datos personales."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó."
                          }
                        },
                        "required": [
                          "id",
                          "action",
                          "screen",
                          "result",
                          "handler_status",
                          "duration_ms",
                          "handler_duration_ms",
                          "request_bytes",
                          "response_bytes",
                          "error",
                          "created_at"
                        ]
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Cambiar clave de los Flows",
        "description": "Genera un par RSA 2048 nuevo para la cuenta (WABA) de la conexión y lo envía a todos los números activos; la clave anterior aún descifra durante 24 h. Permiso: `admin`.",
        "tags": [
          "flows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "description": "ID de la conexión de WhatsApp. Opcional con una clave de conexión (usa la conexión de la clave)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Huella y envíos por número.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "fingerprint": {
                      "type": "string",
                      "description": "SHA-256 de la clave pública nueva."
                    },
                    "uploads": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {
                        "type": "object",
                        "properties": {
                          "uploaded_at": {
                            "type": "string",
                            "description": "Cuándo se envió la clave al número."
                          },
                          "signature_status": {
                            "enum": [
                              "VALID",
                              "MISMATCH",
                              "unknown"
                            ],
                            "type": "string",
                            "description": "`VALID`, `MISMATCH` o `unknown`."
                          },
                          "error": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Error de Meta en el envío, si lo hubo."
                          }
                        },
                        "required": [
                          "uploaded_at",
                          "signature_status",
                          "error"
                        ]
                      },
                      "description": "Envío de la clave 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 conocidos de la organización; con `connection_id`, solo los de la cuenta de mensajes (WABA) de la conexión. Una clave limitada a conexiones debe enviar `connection_id`. Permiso: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión de 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 del catálogo en Messajo (`cat_…`).",
                            "examples": [
                              "cat_0193a1b2c3d47e8f"
                            ]
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID del catálogo o del producto en Meta."
                          },
                          "messaging_account_id": {
                            "type": "string",
                            "description": "Cuenta de mensajes (WABA) del catálogo."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nombre."
                          },
                          "vertical": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Vertical del catálogo en Meta (por ejemplo `commerce`)."
                          },
                          "product_count": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cantidad de productos informada por Meta."
                          },
                          "linked": {
                            "type": "boolean",
                            "description": "Si el catálogo está vinculado a la WABA ahora."
                          },
                          "linked_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo se vinculó (ISO 8601)."
                          },
                          "commerce_settings": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string"
                            },
                            "additionalProperties": {},
                            "description": "Última configuración de comercio leída, por `phone_number_id`."
                          },
                          "last_synced_at": {
                            "type": "string",
                            "description": "Última lectura en Meta (ISO 8601)."
                          }
                        },
                        "required": [
                          "id",
                          "external_id",
                          "messaging_account_id",
                          "name",
                          "vertical",
                          "product_count",
                          "linked",
                          "linked_at",
                          "commerce_settings",
                          "last_synced_at"
                        ]
                      },
                      "description": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Crear catálogo",
        "description": "Crea el catálogo en el portafolio comercial de la conexión y lo vincula a la WABA. Requiere un token con `catalog_management` (`403 commerce_permission_missing` sin él). Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión de WhatsApp (`con_…`)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nombre."
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El catálogo creado y vinculado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del catálogo en Messajo (`cat_…`).",
                      "examples": [
                        "cat_0193a1b2c3d47e8f"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del catálogo o del producto en Meta."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Cuenta de mensajes (WABA) del catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Vertical del catálogo en Meta (por ejemplo `commerce`)."
                    },
                    "product_count": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cantidad de productos informada por Meta."
                    },
                    "linked": {
                      "type": "boolean",
                      "description": "Si el catálogo está vinculado a la WABA ahora."
                    },
                    "linked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se vinculó (ISO 8601)."
                    },
                    "commerce_settings": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Última configuración de comercio leída, por `phone_number_id`."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en 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": "Vincular catálogo",
        "description": "Vincula a la WABA de la conexión un catálogo que ya existe en Meta (`catalog_external_id`). Una WABA tiene como máximo un catálogo vinculado. Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión de WhatsApp (`con_…`)."
                  },
                  "catalog_external_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID del catálogo o del producto en Meta."
                  }
                },
                "required": [
                  "catalog_external_id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El catálogo vinculado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del catálogo en Messajo (`cat_…`).",
                      "examples": [
                        "cat_0193a1b2c3d47e8f"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del catálogo o del producto en Meta."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Cuenta de mensajes (WABA) del catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Vertical del catálogo en Meta (por ejemplo `commerce`)."
                    },
                    "product_count": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cantidad de productos informada por Meta."
                    },
                    "linked": {
                      "type": "boolean",
                      "description": "Si el catálogo está vinculado a la WABA ahora."
                    },
                    "linked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se vinculó (ISO 8601)."
                    },
                    "commerce_settings": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Última configuración de comercio leída, por `phone_number_id`."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en 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": "Desvincular catálogo",
        "description": "Desvincula el catálogo de la WABA de la conexión; el catálogo sigue en el portafolio. Catálogo de otra WABA → `409 catalog_not_linked`. Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del catálogo en Messajo (`cat_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión de WhatsApp (`con_…`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El catálogo desvinculado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del catálogo en Messajo (`cat_…`).",
                      "examples": [
                        "cat_0193a1b2c3d47e8f"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del catálogo o del producto en Meta."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Cuenta de mensajes (WABA) del catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Vertical del catálogo en Meta (por ejemplo `commerce`)."
                    },
                    "product_count": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cantidad de productos informada por Meta."
                    },
                    "linked": {
                      "type": "boolean",
                      "description": "Si el catálogo está vinculado a la WABA ahora."
                    },
                    "linked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se vinculó (ISO 8601)."
                    },
                    "commerce_settings": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Última configuración de comercio leída, por `phone_number_id`."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en 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": "Vuelve a leer de Meta los productos del catálogo y actualiza la caché usada para validar `retailer_id` en el envío. Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del catálogo en Messajo (`cat_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "El catálogo sincronizado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del catálogo en Messajo (`cat_…`).",
                      "examples": [
                        "cat_0193a1b2c3d47e8f"
                      ]
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del catálogo o del producto en Meta."
                    },
                    "messaging_account_id": {
                      "type": "string",
                      "description": "Cuenta de mensajes (WABA) del catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre."
                    },
                    "vertical": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Vertical del catálogo en Meta (por ejemplo `commerce`)."
                    },
                    "product_count": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cantidad de productos informada por Meta."
                    },
                    "linked": {
                      "type": "boolean",
                      "description": "Si el catálogo está vinculado a la WABA ahora."
                    },
                    "linked_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo se vinculó (ISO 8601)."
                    },
                    "commerce_settings": {
                      "type": "object",
                      "propertyNames": {
                        "type": "string"
                      },
                      "additionalProperties": {},
                      "description": "Última configuración de comercio leída, por `phone_number_id`."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en 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 configuración de comercio",
        "description": "Carrito activado y catálogo visible en el perfil del número, leídos de Meta. Permiso: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión de WhatsApp (`con_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La configuración del número.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "is_cart_enabled": {
                      "type": "boolean",
                      "description": "Carrito activado en el número."
                    },
                    "is_catalog_visible": {
                      "type": "boolean",
                      "description": "Catálogo visible en el perfil del 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": "Cambiar configuración de comercio",
        "description": "Activa o desactiva el carrito y la visibilidad del catálogo en el número. Envía al menos un campo. Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión de WhatsApp (`con_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "is_cart_enabled": {
                    "type": "boolean",
                    "description": "Carrito activado en el número."
                  },
                  "is_catalog_visible": {
                    "type": "boolean",
                    "description": "Catálogo visible en el perfil del número."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La configuración después del cambio.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "is_cart_enabled": {
                      "type": "boolean",
                      "description": "Carrito activado en el número."
                    },
                    "is_catalog_visible": {
                      "type": "boolean",
                      "description": "Catálogo visible en el perfil del 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 productos",
        "description": "Productos del catálogo en la caché de Messajo (sincronizada a diario y con `POST /catalogs/{id}/sync`). Permiso: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del catálogo en Messajo (`cat_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Productos.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID del producto en Messajo (`prd_…`).",
                            "examples": [
                              "prd_0193a1b2c3d47e8f"
                            ]
                          },
                          "catalog_id": {
                            "type": "string",
                            "description": "ID del catálogo en Messajo (`cat_…`)."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID del catálogo o del producto en Meta."
                          },
                          "retailer_id": {
                            "type": "string",
                            "description": "SKU del producto (`retailer_id`), único en el catálogo."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nombre."
                          },
                          "description": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Descripción."
                          },
                          "amount_minor": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Precio en unidad menor (centavos), entero."
                          },
                          "sale_amount_minor": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Precio de oferta en unidad menor (centavos)."
                          },
                          "currency": {
                            "type": "string",
                            "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                          },
                          "availability": {
                            "type": "string",
                            "description": "Disponibilidad (`in stock`, `out of stock`, …)."
                          },
                          "condition": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Condición: `new`, `refurbished` o `used`."
                          },
                          "visibility": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Visibilidad en Meta: `published` o `staging`."
                          },
                          "image_url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "URL `https` pública de la imagen."
                          },
                          "url": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "URL `https` de la página del producto."
                          },
                          "brand": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Marca."
                          },
                          "review_status": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Estado de la revisión de Meta."
                          },
                          "last_synced_at": {
                            "type": "string",
                            "description": "Última lectura en 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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Crear producto",
        "description": "Crea el producto en el catálogo de Meta. Precio en unidad menor (`amount_minor`, entero: R$ 59,90 = `5990`). Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del catálogo en 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 del producto (`retailer_id`), único en el catálogo."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nombre."
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 9999,
                    "description": "Descripción."
                  },
                  "amount_minor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Precio en unidad menor (centavos), entero."
                  },
                  "sale_amount_minor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Precio de oferta en unidad menor (centavos)."
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                  },
                  "availability": {
                    "enum": [
                      "in stock",
                      "out of stock",
                      "preorder",
                      "available for order",
                      "discontinued"
                    ],
                    "type": "string",
                    "description": "Disponibilidad (`in stock`, `out of stock`, …)."
                  },
                  "condition": {
                    "enum": [
                      "new",
                      "refurbished",
                      "used"
                    ],
                    "type": "string",
                    "description": "Condición: `new`, `refurbished` o `used`."
                  },
                  "visibility": {
                    "enum": [
                      "published",
                      "staging"
                    ],
                    "type": "string",
                    "description": "Visibilidad en Meta: `published` o `staging`."
                  },
                  "image_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL `https` pública de la imagen."
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL `https` de la página del producto."
                  },
                  "brand": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Marca."
                  }
                },
                "required": [
                  "retailer_id",
                  "name",
                  "amount_minor",
                  "currency",
                  "image_url"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "El producto creado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del producto en Messajo (`prd_…`).",
                      "examples": [
                        "prd_0193a1b2c3d47e8f"
                      ]
                    },
                    "catalog_id": {
                      "type": "string",
                      "description": "ID del catálogo en Messajo (`cat_…`)."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del catálogo o del producto en Meta."
                    },
                    "retailer_id": {
                      "type": "string",
                      "description": "SKU del producto (`retailer_id`), único en el catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción."
                    },
                    "amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Precio en unidad menor (centavos), entero."
                    },
                    "sale_amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Precio de oferta en unidad menor (centavos)."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                    },
                    "availability": {
                      "type": "string",
                      "description": "Disponibilidad (`in stock`, `out of stock`, …)."
                    },
                    "condition": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Condición: `new`, `refurbished` o `used`."
                    },
                    "visibility": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Visibilidad en Meta: `published` o `staging`."
                    },
                    "image_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` pública de la imagen."
                    },
                    "url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` de la página del producto."
                    },
                    "brand": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Marca."
                    },
                    "review_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado de la revisión de Meta."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en 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 producto",
        "description": "Un producto de la caché, con el estado de revisión de Meta. Permiso: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del producto en Messajo (`prd_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El producto.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del producto en Messajo (`prd_…`).",
                      "examples": [
                        "prd_0193a1b2c3d47e8f"
                      ]
                    },
                    "catalog_id": {
                      "type": "string",
                      "description": "ID del catálogo en Messajo (`cat_…`)."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del catálogo o del producto en Meta."
                    },
                    "retailer_id": {
                      "type": "string",
                      "description": "SKU del producto (`retailer_id`), único en el catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción."
                    },
                    "amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Precio en unidad menor (centavos), entero."
                    },
                    "sale_amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Precio de oferta en unidad menor (centavos)."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                    },
                    "availability": {
                      "type": "string",
                      "description": "Disponibilidad (`in stock`, `out of stock`, …)."
                    },
                    "condition": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Condición: `new`, `refurbished` o `used`."
                    },
                    "visibility": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Visibilidad en Meta: `published` o `staging`."
                    },
                    "image_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` pública de la imagen."
                    },
                    "url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` de la página del producto."
                    },
                    "brand": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Marca."
                    },
                    "review_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado de la revisión de Meta."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en 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": "Cambiar producto",
        "description": "Cambia campos del producto en Meta; solo cambian los campos enviados. Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del producto en Messajo (`prd_…`)."
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Nombre."
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 9999,
                    "description": "Descripción."
                  },
                  "amount_minor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Precio en unidad menor (centavos), entero."
                  },
                  "sale_amount_minor": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991,
                    "description": "Precio de oferta en unidad menor (centavos)."
                  },
                  "currency": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 3,
                    "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                  },
                  "availability": {
                    "enum": [
                      "in stock",
                      "out of stock",
                      "preorder",
                      "available for order",
                      "discontinued"
                    ],
                    "type": "string",
                    "description": "Disponibilidad (`in stock`, `out of stock`, …)."
                  },
                  "condition": {
                    "enum": [
                      "new",
                      "refurbished",
                      "used"
                    ],
                    "type": "string",
                    "description": "Condición: `new`, `refurbished` o `used`."
                  },
                  "visibility": {
                    "enum": [
                      "published",
                      "staging"
                    ],
                    "type": "string",
                    "description": "Visibilidad en Meta: `published` o `staging`."
                  },
                  "image_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL `https` pública de la imagen."
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL `https` de la página del producto."
                  },
                  "brand": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Marca."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El producto cambiado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del producto en Messajo (`prd_…`).",
                      "examples": [
                        "prd_0193a1b2c3d47e8f"
                      ]
                    },
                    "catalog_id": {
                      "type": "string",
                      "description": "ID del catálogo en Messajo (`cat_…`)."
                    },
                    "external_id": {
                      "type": "string",
                      "description": "ID del catálogo o del producto en Meta."
                    },
                    "retailer_id": {
                      "type": "string",
                      "description": "SKU del producto (`retailer_id`), único en el catálogo."
                    },
                    "name": {
                      "type": "string",
                      "description": "Nombre."
                    },
                    "description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Descripción."
                    },
                    "amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Precio en unidad menor (centavos), entero."
                    },
                    "sale_amount_minor": {
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -9007199254740991,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Precio de oferta en unidad menor (centavos)."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                    },
                    "availability": {
                      "type": "string",
                      "description": "Disponibilidad (`in stock`, `out of stock`, …)."
                    },
                    "condition": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Condición: `new`, `refurbished` o `used`."
                    },
                    "visibility": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Visibilidad en Meta: `published` o `staging`."
                    },
                    "image_url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` pública de la imagen."
                    },
                    "url": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "URL `https` de la página del producto."
                    },
                    "brand": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Marca."
                    },
                    "review_status": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Estado de la revisión de Meta."
                    },
                    "last_synced_at": {
                      "type": "string",
                      "description": "Última lectura en 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": "Eliminar producto",
        "description": "Elimina el producto en Meta y lo quita de la caché. Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del producto en Messajo (`prd_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmación.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del producto en Messajo (`prd_…`)."
                    },
                    "deleted": {
                      "const": true,
                      "description": "Siempre `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 de la organización, los más recientes primero: carritos recibidos (`cart`) y cobros enviados con `order_details`. Una clave limitada a conexiones solo ve los de sus conexiones. Permiso: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "Cursor de la página siguiente: el `next_cursor` de la respuesta anterior."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50,
              "description": "Elementos por página, de 1 a 100 (por defecto 50)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID de la conexión de WhatsApp (`con_…`)."
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "cart_received",
                "pending",
                "processing",
                "partially_shipped",
                "shipped",
                "completed",
                "canceled"
              ],
              "type": "string",
              "description": "Estado del 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 del pedido (`ord_…`).",
                            "examples": [
                              "ord_0193a1b2c3d47e8f"
                            ]
                          },
                          "connection_id": {
                            "type": "string",
                            "description": "ID de la conexión de WhatsApp (`con_…`)."
                          },
                          "origin": {
                            "enum": [
                              "cart",
                              "order_details"
                            ],
                            "type": "string",
                            "description": "Origen: `cart` (carrito del cliente) u `order_details` (cobro enviado)."
                          },
                          "reference_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "`reference_id` del `order_details`, único en la conexión."
                          },
                          "catalog_id": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "ID del catálogo en Messajo (`cat_…`)."
                          },
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "retailer_id": {
                                  "type": "string",
                                  "description": "SKU del producto (`retailer_id`), único en el catálogo."
                                },
                                "name": {
                                  "anyOf": [
                                    {
                                      "type": "string"
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ],
                                  "description": "Nombre."
                                },
                                "quantity": {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991,
                                  "description": "Cantidad."
                                },
                                "amount_minor": {
                                  "type": "integer",
                                  "minimum": -9007199254740991,
                                  "maximum": 9007199254740991,
                                  "description": "Precio en unidad menor (centavos), entero."
                                },
                                "sale_amount_minor": {
                                  "anyOf": [
                                    {
                                      "type": "integer",
                                      "minimum": -9007199254740991,
                                      "maximum": 9007199254740991,
                                      "description": "Precio de oferta en unidad menor (centavos)."
                                    },
                                    {
                                      "type": "null"
                                    }
                                  ]
                                },
                                "currency": {
                                  "type": "string",
                                  "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                                }
                              },
                              "required": [
                                "retailer_id",
                                "name",
                                "quantity",
                                "amount_minor",
                                "sale_amount_minor",
                                "currency"
                              ]
                            },
                            "description": "Ítems del pedido."
                          },
                          "currency": {
                            "type": "string",
                            "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                          },
                          "subtotal_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Subtotal en unidad menor."
                          },
                          "tax_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Impuestos en unidad menor."
                          },
                          "shipping_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Envío en unidad menor."
                          },
                          "discount_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Descuento en unidad menor."
                          },
                          "total_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Total en unidad menor."
                          },
                          "status": {
                            "enum": [
                              "cart_received",
                              "pending",
                              "processing",
                              "partially_shipped",
                              "shipped",
                              "completed",
                              "canceled"
                            ],
                            "type": "string",
                            "description": "Estado del pedido."
                          },
                          "status_description": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Texto del último `order_status`."
                          },
                          "payment_status": {
                            "enum": [
                              "none",
                              "pending",
                              "captured",
                              "failed",
                              "expired",
                              "unknown"
                            ],
                            "type": "string",
                            "description": "Estado del pago."
                          },
                          "payment_method": {
                            "anyOf": [
                              {
                                "enum": [
                                  "pix_dynamic_code",
                                  "payment_link",
                                  "boleto",
                                  "offsite_card"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Medio de pago informado."
                          },
                          "expires_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Cuándo vence el cobro (ISO 8601)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Creación (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": "Elementos de la página, del más nuevo al más antiguo."
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cursor de la página siguiente; `null` cuando no hay más elementos."
                    }
                  },
                  "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": "Un pedido con ítems, totales en unidad menor, estado y estado del pago. Permiso: `read`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del pedido (`ord_…`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "El pedido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del pedido (`ord_…`).",
                      "examples": [
                        "ord_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp (`con_…`)."
                    },
                    "origin": {
                      "enum": [
                        "cart",
                        "order_details"
                      ],
                      "type": "string",
                      "description": "Origen: `cart` (carrito del cliente) u `order_details` (cobro enviado)."
                    },
                    "reference_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`reference_id` del `order_details`, único en la conexión."
                    },
                    "catalog_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del catálogo en Messajo (`cat_…`)."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "retailer_id": {
                            "type": "string",
                            "description": "SKU del producto (`retailer_id`), único en el catálogo."
                          },
                          "name": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre."
                          },
                          "quantity": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Cantidad."
                          },
                          "amount_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Precio en unidad menor (centavos), entero."
                          },
                          "sale_amount_minor": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Precio de oferta en unidad menor (centavos)."
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "currency": {
                            "type": "string",
                            "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                          }
                        },
                        "required": [
                          "retailer_id",
                          "name",
                          "quantity",
                          "amount_minor",
                          "sale_amount_minor",
                          "currency"
                        ]
                      },
                      "description": "Ítems del pedido."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                    },
                    "subtotal_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Subtotal en unidad menor."
                    },
                    "tax_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Impuestos en unidad menor."
                    },
                    "shipping_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Envío en unidad menor."
                    },
                    "discount_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Descuento en unidad menor."
                    },
                    "total_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Total en unidad menor."
                    },
                    "status": {
                      "enum": [
                        "cart_received",
                        "pending",
                        "processing",
                        "partially_shipped",
                        "shipped",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado del pedido."
                    },
                    "status_description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto del último `order_status`."
                    },
                    "payment_status": {
                      "enum": [
                        "none",
                        "pending",
                        "captured",
                        "failed",
                        "expired",
                        "unknown"
                      ],
                      "type": "string",
                      "description": "Estado del pago."
                    },
                    "payment_method": {
                      "anyOf": [
                        {
                          "enum": [
                            "pix_dynamic_code",
                            "payment_link",
                            "boleto",
                            "offsite_card"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Medio de pago informado."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo vence el cobro (ISO 8601)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Creación (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 pago",
        "description": "El Pix fuera de WhatsApp no tiene webhook de pago: concilia con tu PSP e informa aquí `captured` o `failed`. Con `notify: true` y `captured`, Messajo envía al cliente el `order_status processing` (texto en `message`). Solo pedidos `pending` aún no pagados; si no, `409 order_invalid_transition`. Permiso: `commerce`.",
        "tags": [
          "commerce"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "description": "ID del pedido (`ord_…`)."
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "enum": [
                      "captured",
                      "failed"
                    ],
                    "type": "string",
                    "description": "Resultado de la conciliación: `captured` o `failed`."
                  },
                  "notify": {
                    "type": "boolean",
                    "description": "Con `captured`, envía al cliente el `order_status processing`."
                  },
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1024,
                    "description": "Texto del aviso al cliente (hasta 1024 caracteres)."
                  }
                },
                "required": [
                  "status"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "El pedido actualizado y el ID del mensaje de aviso, si lo hubo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "ID del pedido (`ord_…`).",
                      "examples": [
                        "ord_0193a1b2c3d47e8f"
                      ]
                    },
                    "connection_id": {
                      "type": "string",
                      "description": "ID de la conexión de WhatsApp (`con_…`)."
                    },
                    "origin": {
                      "enum": [
                        "cart",
                        "order_details"
                      ],
                      "type": "string",
                      "description": "Origen: `cart` (carrito del cliente) u `order_details` (cobro enviado)."
                    },
                    "reference_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "`reference_id` del `order_details`, único en la conexión."
                    },
                    "catalog_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del catálogo en Messajo (`cat_…`)."
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "retailer_id": {
                            "type": "string",
                            "description": "SKU del producto (`retailer_id`), único en el catálogo."
                          },
                          "name": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Nombre."
                          },
                          "quantity": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Cantidad."
                          },
                          "amount_minor": {
                            "type": "integer",
                            "minimum": -9007199254740991,
                            "maximum": 9007199254740991,
                            "description": "Precio en unidad menor (centavos), entero."
                          },
                          "sale_amount_minor": {
                            "anyOf": [
                              {
                                "type": "integer",
                                "minimum": -9007199254740991,
                                "maximum": 9007199254740991,
                                "description": "Precio de oferta en unidad menor (centavos)."
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "currency": {
                            "type": "string",
                            "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                          }
                        },
                        "required": [
                          "retailer_id",
                          "name",
                          "quantity",
                          "amount_minor",
                          "sale_amount_minor",
                          "currency"
                        ]
                      },
                      "description": "Ítems del pedido."
                    },
                    "currency": {
                      "type": "string",
                      "description": "Moneda ISO 4217 (por ejemplo `BRL`)."
                    },
                    "subtotal_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Subtotal en unidad menor."
                    },
                    "tax_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Impuestos en unidad menor."
                    },
                    "shipping_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Envío en unidad menor."
                    },
                    "discount_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Descuento en unidad menor."
                    },
                    "total_minor": {
                      "type": "integer",
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991,
                      "description": "Total en unidad menor."
                    },
                    "status": {
                      "enum": [
                        "cart_received",
                        "pending",
                        "processing",
                        "partially_shipped",
                        "shipped",
                        "completed",
                        "canceled"
                      ],
                      "type": "string",
                      "description": "Estado del pedido."
                    },
                    "status_description": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Texto del último `order_status`."
                    },
                    "payment_status": {
                      "enum": [
                        "none",
                        "pending",
                        "captured",
                        "failed",
                        "expired",
                        "unknown"
                      ],
                      "type": "string",
                      "description": "Estado del pago."
                    },
                    "payment_method": {
                      "anyOf": [
                        {
                          "enum": [
                            "pix_dynamic_code",
                            "payment_link",
                            "boleto",
                            "offsite_card"
                          ],
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Medio de pago informado."
                    },
                    "expires_at": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Cuándo vence el cobro (ISO 8601)."
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Creación (ISO 8601)."
                    },
                    "notification_message_id": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "ID del mensaje de aviso enviado, o `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": "Crear plantilla de autenticación",
        "description": "Crea (o actualiza) una plantilla `AUTHENTICATION` en cada idioma, con botón copy code, one-tap o zero-tap. El texto es el fijo de Meta. Envía después el código con `POST /messages` `type: \"otp\"`: el código va solo a Meta y se guarda enmascarado. Permiso: `templates`.",
        "tags": [
          "templates"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión de 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 ejemplo `es`."
                  },
                  "add_security_recommendation": {
                    "type": "boolean",
                    "description": "Añade el aviso de seguridad de Meta al cuerpo."
                  },
                  "code_expiration_minutes": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 90,
                    "description": "Validez del código en minutos (1 a 90), mostrada en el pie."
                  },
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z0-9_]{1,512}$",
                    "description": "Nombre de la plantilla (minúsculas, números y `_`)."
                  },
                  "message_send_ttl_seconds": {
                    "type": "integer",
                    "minimum": 30,
                    "maximum": 900,
                    "description": "Plazo de entrega en 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ón OTP: `COPY_CODE`, `ONE_TAP` o `ZERO_TAP` (estos con `supported_apps`)."
                  }
                },
                "required": [
                  "languages",
                  "add_security_recommendation",
                  "name",
                  "button"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Una plantilla por idioma.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "ID de la plantilla en Messajo (`tpl_…`).",
                            "examples": [
                              "tpl_0193a1b2c3d47e8f9a0b1c2d3e4f5a6b"
                            ]
                          },
                          "messaging_account_id": {
                            "type": "string",
                            "description": "Cuenta de WhatsApp Business (WABA) de la plantilla."
                          },
                          "external_id": {
                            "type": "string",
                            "description": "ID de la plantilla en Meta."
                          },
                          "name": {
                            "type": "string",
                            "description": "Nombre (minúsculas, números y `_`)."
                          },
                          "language": {
                            "type": "string",
                            "description": "Idioma, p. ej., `es`."
                          },
                          "category": {
                            "enum": [
                              "MARKETING",
                              "UTILITY",
                              "AUTHENTICATION"
                            ],
                            "type": "string",
                            "description": "Categoría: `MARKETING`, `UTILITY` o `AUTHENTICATION`."
                          },
                          "previous_category": {
                            "anyOf": [
                              {
                                "enum": [
                                  "MARKETING",
                                  "UTILITY",
                                  "AUTHENTICATION"
                                ],
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Categoría anterior, cuando Meta la reclasificó."
                          },
                          "status": {
                            "enum": [
                              "APPROVED",
                              "PENDING",
                              "REJECTED",
                              "PAUSED",
                              "DISABLED",
                              "IN_APPEAL",
                              "PENDING_DELETION",
                              "DELETED",
                              "ARCHIVED",
                              "LIMIT_EXCEEDED",
                              "LOCKED",
                              "FLAGGED",
                              "REINSTATED"
                            ],
                            "type": "string",
                            "description": "Estado en Meta, p. ej., `APPROVED`, `PENDING`, `REJECTED`."
                          },
                          "rejected_reason": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Motivo del rechazo, cuando lo hay."
                          },
                          "quality_score": {
                            "enum": [
                              "GREEN",
                              "YELLOW",
                              "RED",
                              "UNKNOWN"
                            ],
                            "type": "string",
                            "description": "Calidad: `GREEN`, `YELLOW`, `RED` o `UNKNOWN`."
                          },
                          "parameter_format": {
                            "enum": [
                              "POSITIONAL",
                              "NAMED"
                            ],
                            "type": "string",
                            "description": "Formato de las variables: `POSITIONAL` o `NAMED`."
                          },
                          "components": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            "description": "Componentes en el formato de Meta (`HEADER`, `BODY`, `FOOTER`, `BUTTONS`)."
                          },
                          "last_synced_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Última lectura en Meta (ISO 8601, UTC)."
                          },
                          "status_updated_at": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Último cambio de estado (ISO 8601, UTC)."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "Cuándo se creó en Messajo (ISO 8601, UTC)."
                          },
                          "updated_at": {
                            "type": "string",
                            "description": "Último cambio (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": "Plantillas creadas, una 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": "Previsualizar plantilla de autenticación",
        "description": "Los textos que Meta usará en cada idioma con las opciones elegidas. Permiso: `templates`.",
        "tags": [
          "templates"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "connection_id": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID de la conexión de 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 ejemplo `es`."
                  },
                  "add_security_recommendation": {
                    "type": "boolean",
                    "description": "Añade el aviso de seguridad de Meta al cuerpo."
                  },
                  "code_expiration_minutes": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 90,
                    "description": "Validez del código en minutos (1 a 90), mostrada en el pie."
                  }
                },
                "required": [
                  "languages",
                  "add_security_recommendation"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Previsualizaciones 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": "Cuerpo."
                          },
                          "footer": {
                            "type": "string",
                            "description": "Pie."
                          },
                          "buttons": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "text": {
                                  "type": "string"
                                },
                                "autofill_text": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "text"
                              ]
                            },
                            "description": "Botones."
                          }
                        },
                        "required": [
                          "language",
                          "body",
                          "buttons"
                        ]
                      },
                      "description": "Previsualizaciones 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": "Costos de WhatsApp",
        "description": "Costo cobrado por Meta en el período, en la moneda de la cuenta de WhatsApp. `estimate` lo calcula Messajo al entregarse cada mensaje; `official` es el valor aproximado informado por Meta (llega con hasta 3 días de atraso).",
        "tags": [
          "usage"
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "description": "Primer día (UTC, `AAAA-MM-DD`). Por defecto: día 1 del mes actual"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date",
              "description": "Último día, inclusive. Por defecto: hoy. Máximo 366 días"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "connection_id",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Solo esta conexión"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[A-Z]{3}$",
              "description": "Moneda (ISO 4217). Obligatoria cuando la organización tiene cuentas en más de una moneda"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          },
          {
            "name": "group_by",
            "in": "query",
            "schema": {
              "enum": [
                "day",
                "campaign",
                "template",
                "category",
                "connection"
              ],
              "type": "string",
              "default": "day",
              "description": "Agrupamiento: día, campaña, plantilla, conexión o categoría"
            },
            "allowEmptyValue": true,
            "allowReserved": true
          }
        ],
        "responses": {
          "200": {
            "description": "Ítems del agrupamiento pedido",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "currency": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "description": "Moneda de los valores; `null` si la organización aún no tiene costo"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string",
                            "description": "Día (`AAAA-MM-DD`), id de la campaña, `nombre:idioma` de la plantilla, id de la conexión o categoría"
                          },
                          "estimate": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Estimación de Messajo (cadena decimal); `null` si no se puede estimar"
                          },
                          "official": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ],
                            "description": "Valor aproximado de Meta (cadena decimal); `null` mientras Meta no lo informa. Ausente al agrupar por campaña o plantilla"
                          }
                        },
                        "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": "Espejo de Meta (lectura)",
        "description": "Reenvía un `GET` a la Graph API de Meta con el token de la conexión, sin cambiar el cuerpo ni la respuesta (los errores de Meta vuelven como Meta los envió). `{id}` es el `phone_number_id` o el `messaging_account_id` (WABA) de una conexión de la organización; los nodos sueltos van en `{phone_number_id}/nodes/{node_id}`. Referencia de las rutas: https://developers.facebook.com/docs/whatsapp/cloud-api. Permiso: `read` (plantillas: `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` o `messaging_account_id` de una conexión de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, p. ej., `messages`, `message_templates` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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": "Espejo de Meta (escritura)",
        "description": "Reenvía un `POST` a la Graph API de Meta con el token de la conexión. `POST …/messages` respeta el límite de mensajes por segundo del número, guarda el mensaje y devuelve el ID en el encabezado `X-Messajo-Message-Id`. Las rutas que rompen la conexión (`register`, `deregister`, `request_code`, `verify_code`, `smb_app_data`, `subscribed_apps` con `override_callback_uri`) se rechazan con `403 mirror_path_blocked`. Permiso: `send` para mensajes, `templates` para plantillas, `admin` para el 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` o `messaging_account_id` de una conexión de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, p. ej., `messages`, `message_templates` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "description": "Cuerpo en el formato de la Graph API, reenviado tal cual.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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": "Espejo de Meta (eliminación)",
        "description": "Reenvía un `DELETE` a la Graph API de Meta con el token de la conexión. `DELETE …/subscribed_apps` se rechaza (`403 mirror_path_blocked`). Permiso: `templates` para plantillas, `admin` para el 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` o `messaging_account_id` de una conexión de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, p. ej., `messages`, `message_templates` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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": "Espejo de Instagram (lectura)",
        "description": "Reenvía un `GET` a la Graph API de Instagram con el token de la cuenta, sin cambiar el cuerpo ni la respuesta (los errores de Meta vuelven como Meta los mandó). `{ig_user_id}` es una cuenta de la organización; los nodos sueltos (contenido, comentario, contenedor) están en `{ig_user_id}/nodes/{node_id}`. Referencia: https://developers.facebook.com/docs/instagram-platform. Permiso: `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 una cuenta de Instagram de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, por ejemplo `messages`, `media` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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": "Espejo de Instagram (escritura)",
        "description": "Reenvía un `POST` a la Graph API de Instagram con el token de la cuenta. `POST …/messages` respeta el límite de mensajes por segundo, guarda el mensaje y devuelve su ID en la cabecera `X-Messajo-Message-Id`. `media_publish` por el espejo no se vuelve una publicación programable (usa `POST /publications`). Las rutas que rompen la conexión (`subscribed_apps`, `access_token`, `oauth/*`) se rechazan con `403 mirror_path_blocked`. Permiso: `send` para mensajes, multimedia, publicación y comentarios; `admin` para el 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 una cuenta de Instagram de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, por ejemplo `messages`, `media` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "description": "Cuerpo en el formato de la Graph API, reenviado tal cual.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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": "Espejo de Instagram (borrado)",
        "description": "Reenvía un `DELETE` a la Graph API de Instagram con el token de la cuenta. Borrar un comentario exige `send`; el resto, `admin`. `subscribed_apps` se rechaza (`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 una cuenta de Instagram de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, por ejemplo `messages`, `media` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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": "Espejo de Messenger (lectura)",
        "description": "Reenvía un `GET` a la Graph API de Facebook con el token de la Página, sin cambiar el cuerpo ni la respuesta. `{page_id}` es una Página de la organización; los nodos sueltos están en `{page_id}/nodes/{node_id}`. Referencia: https://developers.facebook.com/docs/messenger-platform. Permiso: `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 una Página de Facebook de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, por ejemplo `messages`, `media` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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": "Espejo de Messenger (escritura)",
        "description": "Reenvía un `POST` a la Graph API de Facebook con el token de la Página. `POST …/messages` respeta el límite de mensajes por segundo, guarda el mensaje y devuelve su ID en `X-Messajo-Message-Id`. `subscribed_apps`, `access_token` y `oauth/*` se rechazan (`403 mirror_path_blocked`); `pass_thread_control`/`take_thread_control` exigen `admin`. Permiso: `send` para mensajes y adjuntos, `admin` para el 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 una Página de Facebook de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, por ejemplo `messages`, `media` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "description": "Cuerpo en el formato de la Graph API, reenviado tal cual.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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": "Espejo de Messenger (borrado)",
        "description": "Reenvía un `DELETE` a la Graph API de Facebook con el token de la Página. `subscribed_apps` se rechaza (`403 mirror_path_blocked`). Permiso: `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 una Página de Facebook de la organización.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "description": "Resto de la ruta de la Graph API, por ejemplo `messages`, `media` o `nodes/{node_id}`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "La respuesta de Meta, tal como llegó.",
            "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"
          }
        }
      }
    }
  }
}
