{
  "openapi": "3.1.0",
  "info": {
    "title": "Oneos — API de Integração",
    "version": "1.0.0",
    "summary": "Pré-autorizações de antecipação de recebíveis e webhooks assinados.",
    "description": "API pública para conectar o ERP de uma construtora à Oneos. Somente produção. Dentro da v1 só entram mudanças compatíveis; mudança incompatível vai para /api/integration/v2, anunciada com pelo menos 90 dias de antecedência (https://docs.oneos.com.br/api/changelog/). Documentação: https://docs.oneos.com.br/api/",
    "contact": {
      "name": "Oneos",
      "url": "https://docs.oneos.com.br"
    }
  },
  "servers": [
    {
      "url": "https://app.oneos.com.br/api",
      "description": "Produção"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Pré-autorizações"
    }
  ],
  "paths": {
    "/integration/v1/pre-authorizations": {
      "get": {
        "tags": [
          "Pré-autorizações"
        ],
        "operationId": "listPreAuthorizations",
        "summary": "Listar pré-autorizações",
        "description": "Operações em que a sua empresa (matriz ou filial) é a tomadora, da mais recente para a mais antiga. Inclui antecipações diretas. Escopo: preauth:read.",
        "parameters": [
          {
            "name": "externalReference",
            "in": "query",
            "required": false,
            "description": "Igualdade exata com o externalReference enviado na criação.",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "Um ou mais status. Repita o parâmetro: ?status=IN_PRE_AUTH&status=TO_APPROVE.",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "IN_PRE_AUTH",
                  "IN_VERIFICATION",
                  "TO_APPROVE",
                  "IN_ANALYSIS",
                  "TO_PAY",
                  "TO_BILL",
                  "TO_RECEIVE",
                  "CONCLUDED",
                  "REPROVED"
                ]
              }
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Página de operações.",
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                },
                "description": "Requisições permitidas na janela (120)."
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                },
                "description": "Requisições restantes na janela."
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                },
                "description": "Segundos até a janela reiniciar."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreAuthorizationList"
                }
              }
            }
          },
          "400": {
            "description": "Query inválida (VALIDATION_ERROR).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida, revogada ou expirada (API_KEY_INVALID, API_KEY_REVOKED, API_KEY_EXPIRED).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "403": {
            "description": "Chave sem o escopo, ou usuário responsável sem permissão (INTEGRATION_SCOPE_FORBIDDEN, INTEGRATION_RESPONSIBLE_FORBIDDEN, RBAC_FORBIDDEN).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (RATE_LIMITED).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Segundos até poder tentar de novo."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (INTERNAL_ERROR).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Pré-autorizações"
        ],
        "operationId": "createPreAuthorization",
        "summary": "Criar pré-autorização",
        "description": "Cria uma pré-autorização com a sua empresa (matriz) como tomadora. O fornecedor é avisado para antecipar. Escopo: preauth:write.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "8 a 100 caracteres [A-Za-z0-9._:-]. Repetir a mesma chave com o mesmo corpo devolve a resposta original.",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 100,
              "pattern": "^[A-Za-z0-9._:-]+$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "supplier": {
                    "type": "object",
                    "properties": {
                      "cnpj": {
                        "type": "string",
                        "description": "CNPJ do fornecedor, com ou sem máscara. Dígitos verificadores são conferidos; CNPJ alfanumérico é aceito."
                      },
                      "email": {
                        "type": "string",
                        "maxLength": 255,
                        "format": "email",
                        "pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
                        "description": "E-mail de contato do fornecedor para esta operação."
                      },
                      "name": {
                        "type": "string",
                        "minLength": 2,
                        "maxLength": 255,
                        "description": "Razão social. Obrigatório quando o CNPJ ainda não está na Oneos — sem ele a API responde 422 PRE_AUTH_SUPPLIER_NAME_REQUIRED. Para fornecedor já cadastrado, é ignorado."
                      },
                      "contactName": {
                        "type": "string",
                        "minLength": 2,
                        "maxLength": 255,
                        "description": "Nome da pessoa de contato. Obrigatório junto com supplier.name quando o CNPJ é novo."
                      },
                      "phone": {
                        "type": "string",
                        "maxLength": 20,
                        "description": "Telefone do contato."
                      }
                    },
                    "required": [
                      "cnpj",
                      "email"
                    ],
                    "description": "Fornecedor que vai receber a oferta de antecipação."
                  },
                  "invoice": {
                    "type": "object",
                    "properties": {
                      "amount": {
                        "type": "number",
                        "minimum": 500,
                        "maximum": 10000000,
                        "description": "Valor bruto da nota, em reais. Aceita número ou string numérica (\"18400.50\")."
                      },
                      "dueDate": {
                        "type": "string",
                        "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                        "description": "Vencimento da nota. Precisa estar entre 5 e 180 dias corridos a partir de hoje (horário de São Paulo) e dentro do prazo máximo do seu limite de crédito."
                      },
                      "number": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 50,
                        "description": "Número da nota fiscal."
                      },
                      "withheldTaxAmount": {
                        "default": 0,
                        "type": "number",
                        "minimum": 0,
                        "description": "Retenções fiscais da nota, em reais. Não pode passar de amount − 500."
                      }
                    },
                    "required": [
                      "amount",
                      "dueDate",
                      "number"
                    ],
                    "description": "Nota fiscal que será antecipada."
                  },
                  "externalReference": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Identificador livre do seu ERP (pedido, título, parcela). Volta em todas as respostas e em todos os webhooks desta operação."
                  }
                },
                "required": [
                  "supplier",
                  "invoice"
                ]
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "supplier",
                  "invoice"
                ],
                "properties": {
                  "supplier": {
                    "type": "string",
                    "description": "Objeto supplier serializado como JSON."
                  },
                  "invoice": {
                    "type": "string",
                    "description": "Objeto invoice serializado como JSON."
                  },
                  "externalReference": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "invoiceFile": {
                    "type": "string",
                    "format": "binary",
                    "description": "Nota fiscal em PDF ou XML, até 10 MB. O Content-Type do part deve ser application/pdf, application/xml ou text/xml."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Pré-autorização criada (ou replay idempotente, com Idempotency-Replayed: true).",
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                },
                "description": "Requisições permitidas na janela (120)."
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                },
                "description": "Requisições restantes na janela."
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                },
                "description": "Segundos até a janela reiniciar."
              },
              "Idempotency-Replayed": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "true"
                  ]
                },
                "description": "Presente só no replay."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreAuthorization"
                }
              }
            }
          },
          "400": {
            "description": "Corpo inválido (VALIDATION_ERROR, um item por problema) ou Idempotency-Key inválido.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida, revogada ou expirada (API_KEY_INVALID, API_KEY_REVOKED, API_KEY_EXPIRED).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "403": {
            "description": "Chave sem o escopo, ou usuário responsável sem permissão (INTEGRATION_SCOPE_FORBIDDEN, INTEGRATION_RESPONSIBLE_FORBIDDEN, RBAC_FORBIDDEN).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "409": {
            "description": "Já existe operação em andamento para a mesma nota do mesmo fornecedor (PRE_AUTH_DUPLICATE_INVOICE, com details[0].anticipationId), Idempotency-Key reusado com outro corpo, ou requisição igual ainda em processamento.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "413": {
            "description": "Arquivo acima de 10 MB (FILE_TOO_LARGE).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "422": {
            "description": "Regra de negócio: vencimento, limite de crédito, fornecedor, tipo de arquivo.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (RATE_LIMITED).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Segundos até poder tentar de novo."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (INTERNAL_ERROR).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          }
        }
      }
    },
    "/integration/v1/pre-authorizations/{id}": {
      "get": {
        "tags": [
          "Pré-autorizações"
        ],
        "operationId": "getPreAuthorization",
        "summary": "Consultar pré-autorização",
        "description": "Devolve a operação com o status atual. Use para reconciliar quando um evento não chegou. Escopo: preauth:read.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "O id devolvido na criação.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A operação, com o status atual.",
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                },
                "description": "Requisições permitidas na janela (120)."
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                },
                "description": "Requisições restantes na janela."
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                },
                "description": "Segundos até a janela reiniciar."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreAuthorization"
                }
              }
            }
          },
          "400": {
            "description": "id não numérico.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida, revogada ou expirada (API_KEY_INVALID, API_KEY_REVOKED, API_KEY_EXPIRED).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "403": {
            "description": "Chave sem o escopo, ou usuário responsável sem permissão (INTEGRATION_SCOPE_FORBIDDEN, INTEGRATION_RESPONSIBLE_FORBIDDEN, RBAC_FORBIDDEN).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "404": {
            "description": "Não existe, ou a sua empresa não é a tomadora (ANTICIPATION_NOT_FOUND).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (RATE_LIMITED).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Segundos até poder tentar de novo."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (INTERNAL_ERROR).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          }
        }
      }
    },
    "/integration/v1/pre-authorizations/{id}/cancel": {
      "post": {
        "tags": [
          "Pré-autorizações"
        ],
        "operationId": "cancelPreAuthorization",
        "summary": "Cancelar pré-autorização",
        "description": "Cancela uma pré-autorização que ainda não foi solicitada pelo fornecedor. Sem corpo. Idempotente: repetir sobre uma pré-autorização que a integração já cancelou devolve 201 com o estado atual, sem novo evento. Escopo: preauth:write.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "O id devolvido na criação.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Cancelada (ou já cancelada pela integração). A operação volta com status REPROVED.",
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                },
                "description": "Requisições permitidas na janela (120)."
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                },
                "description": "Requisições restantes na janela."
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                },
                "description": "Segundos até a janela reiniciar."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreAuthorization"
                }
              }
            }
          },
          "400": {
            "description": "id não numérico.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "401": {
            "description": "Chave ausente, inválida, revogada ou expirada (API_KEY_INVALID, API_KEY_REVOKED, API_KEY_EXPIRED).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "403": {
            "description": "Chave sem o escopo, ou usuário responsável sem permissão (INTEGRATION_SCOPE_FORBIDDEN, INTEGRATION_RESPONSIBLE_FORBIDDEN, RBAC_FORBIDDEN).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "404": {
            "description": "Operação não encontrada (ANTICIPATION_NOT_FOUND).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "409": {
            "description": "A operação mudou de estado durante a chamada (ANTICIPATION_INVALID_TRANSITION). Tente de novo.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "422": {
            "description": "Já solicitada pelo fornecedor (PRE_AUTH_ALREADY_REQUESTED), ou encerrada por outro motivo: recusada, expirada, reprovada ou cancelada fora da integração (PRE_AUTH_ALREADY_CLOSED).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "429": {
            "description": "Limite de requisições atingido (RATE_LIMITED).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Segundos até poder tentar de novo."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          },
          "500": {
            "description": "Erro interno (INTERNAL_ERROR).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "oneosEvent": {
      "post": {
        "summary": "Evento da Oneos",
        "description": "Enviado ao endpoint configurado na plataforma. Tipos: pre_authorization.created (Pré-autorização criada); pre_authorization.declined (Pré-autorização recusada pelo fornecedor); pre_authorization.revoked (Pré-autorização cancelada); pre_authorization.expired (Pré-autorização expirada); anticipation.created (Antecipação criada); anticipation.requested (Antecipação solicitada); anticipation.approved (Antecipação aprovada pela construtora); anticipation.analysis_approved (Análise aprovada (liberada para pagamento)); anticipation.reproved (Antecipação reprovada); anticipation.reopened (Antecipação reaberta para análise); anticipation.paid (Pagamento ao fornecedor realizado); anticipation.payout_returned (Pagamento ao fornecedor devolvido); anticipation.billed (Boleto emitido); anticipation.concluded (Antecipação concluída); anticipation.extension_created (Prorrogação de boleto solicitada); anticipation.extension_concluded (Prorrogação paga (boleto trocado)); anticipation.extension_canceled (Prorrogação cancelada); invoice.received (Nota fiscal recebida); payment_order.created (Ordem de pagamento criada); payment_order.under_review (Ordem de pagamento em análise); payment_order.scheduled (Ordem de pagamento programada); payment_order.paid (Ordem de pagamento paga); payment_order.canceled (Ordem de pagamento cancelada); payment_order.reproved (Ordem de pagamento reprovada); webhook.test (Evento de teste).",
        "parameters": [
          {
            "name": "x-oneos-signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "t=<unix>,v1=<HMAC-SHA256 hex de \"t.corpo\">"
          },
          {
            "name": "x-oneos-event-id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "x-oneos-event-type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "pre_authorization.created",
                "pre_authorization.declined",
                "pre_authorization.revoked",
                "pre_authorization.expired",
                "anticipation.created",
                "anticipation.requested",
                "anticipation.approved",
                "anticipation.analysis_approved",
                "anticipation.reproved",
                "anticipation.reopened",
                "anticipation.paid",
                "anticipation.payout_returned",
                "anticipation.billed",
                "anticipation.concluded",
                "anticipation.extension_created",
                "anticipation.extension_concluded",
                "anticipation.extension_canceled",
                "invoice.received",
                "payment_order.created",
                "payment_order.under_review",
                "payment_order.scheduled",
                "payment_order.paid",
                "payment_order.canceled",
                "payment_order.reproved",
                "webhook.test"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Qualquer 2xx em até 10 s confirma a entrega."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Chave de API da empresa (oneos_sk_…), gerada em Minha empresa › Integração."
      }
    },
    "schemas": {
      "PreAuthorization": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991,
            "description": "Identificador da operação na Oneos. É o {id} da consulta e do cancelamento, e o anticipationId dos webhooks."
          },
          "status": {
            "type": "string",
            "enum": [
              "IN_PRE_AUTH",
              "IN_VERIFICATION",
              "TO_APPROVE",
              "IN_ANALYSIS",
              "TO_PAY",
              "TO_BILL",
              "TO_RECEIVE",
              "CONCLUDED",
              "REPROVED"
            ],
            "description": "Status no momento da resposta. Na criação é sempre IN_PRE_AUTH; no cancelamento, REPROVED; na consulta, o status atual."
          },
          "externalReference": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "O identificador que você enviou, ou null."
          },
          "payer": {
            "type": "object",
            "properties": {
              "cnpj": {
                "type": "string",
                "description": "CNPJ da tomadora, só dígitos."
              },
              "name": {
                "type": "string",
                "description": "Razão social da tomadora."
              }
            },
            "required": [
              "cnpj",
              "name"
            ],
            "additionalProperties": false,
            "description": "A tomadora, que paga a nota. Na criação, a matriz dona da chave; na consulta e no cancelamento, a empresa da nota (a matriz ou uma filial)."
          },
          "supplier": {
            "type": "object",
            "properties": {
              "cnpj": {
                "type": "string",
                "description": "CNPJ normalizado (só dígitos e letras, em maiúsculas)."
              },
              "name": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Nome cadastrado na Oneos, ou null."
              }
            },
            "required": [
              "cnpj",
              "name"
            ],
            "additionalProperties": false,
            "description": "O fornecedor da operação."
          },
          "invoice": {
            "type": "object",
            "properties": {
              "amount": {
                "type": "number",
                "description": "Valor bruto, arredondado em centavos."
              },
              "dueDate": {
                "type": "string",
                "description": "Vencimento, AAAA-MM-DD."
              },
              "number": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Número da nota."
              },
              "withheldTaxAmount": {
                "type": "number",
                "description": "Retenção gravada (0 quando não enviada)."
              }
            },
            "required": [
              "amount",
              "dueDate",
              "number",
              "withheldTaxAmount"
            ],
            "additionalProperties": false,
            "description": "Dados da nota como foram gravados."
          },
          "expiresAt": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Até quando o fornecedor pode solicitar a antecipação. Depois disso a pré-autorização expira sozinha. Veja expiração."
          },
          "createdAt": {
            "type": "string",
            "description": "Momento da criação, ISO 8601 em UTC."
          }
        },
        "required": [
          "id",
          "status",
          "externalReference",
          "payer",
          "supplier",
          "invoice",
          "expiresAt",
          "createdAt"
        ],
        "additionalProperties": false
      },
      "PreAuthorizationList": {
        "type": "object",
        "required": [
          "data",
          "pagination"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PreAuthorization"
            }
          },
          "pagination": {
            "type": "object",
            "required": [
              "page",
              "limit",
              "total",
              "totalPages"
            ],
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1
              },
              "limit": {
                "type": "integer",
                "minimum": 1
              },
              "total": {
                "type": "integer",
                "minimum": 0
              },
              "totalPages": {
                "type": "integer",
                "minimum": 0
              }
            }
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
            "description": "Identificador único do evento. É o mesmo em todas as tentativas e reenvios — use para deduplicar."
          },
          "type": {
            "type": "string",
            "enum": [
              "pre_authorization.created",
              "pre_authorization.declined",
              "pre_authorization.revoked",
              "pre_authorization.expired",
              "anticipation.created",
              "anticipation.requested",
              "anticipation.approved",
              "anticipation.analysis_approved",
              "anticipation.reproved",
              "anticipation.reopened",
              "anticipation.paid",
              "anticipation.payout_returned",
              "anticipation.billed",
              "anticipation.concluded",
              "anticipation.extension_created",
              "anticipation.extension_concluded",
              "anticipation.extension_canceled",
              "invoice.received",
              "payment_order.created",
              "payment_order.under_review",
              "payment_order.scheduled",
              "payment_order.paid",
              "payment_order.canceled",
              "payment_order.reproved",
              "webhook.test"
            ],
            "description": "Tipo do evento, do catálogo."
          },
          "createdAt": {
            "type": "string",
            "description": "Momento em que o evento aconteceu, ISO 8601 em UTC."
          },
          "data": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {},
            "description": "Conteúdo do evento. O formato depende da família do tipo."
          }
        },
        "required": [
          "id",
          "type",
          "createdAt",
          "data"
        ],
        "additionalProperties": false
      },
      "WebhookAnticipationData": {
        "type": "object",
        "properties": {
          "anticipationId": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991,
            "description": "O id da operação — o mesmo da resposta de criação."
          },
          "status": {
            "type": "string",
            "enum": [
              "IN_PRE_AUTH",
              "IN_VERIFICATION",
              "TO_APPROVE",
              "IN_ANALYSIS",
              "TO_PAY",
              "TO_BILL",
              "TO_RECEIVE",
              "CONCLUDED",
              "REPROVED"
            ],
            "description": "Status da operação depois do evento."
          },
          "origin": {
            "type": "string",
            "enum": [
              "PRE_AUTH",
              "DIRECT"
            ],
            "description": "PRE_AUTH quando nasceu de pré-autorização; DIRECT quando o fornecedor antecipou direto."
          },
          "invoice": {
            "type": "object",
            "properties": {
              "amount": {
                "type": "number",
                "description": "Valor bruto."
              },
              "dueDate": {
                "type": "string",
                "description": "Vencimento, AAAA-MM-DD."
              },
              "number": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Número da nota."
              }
            },
            "required": [
              "amount",
              "dueDate",
              "number"
            ],
            "additionalProperties": false,
            "description": "Dados da nota."
          },
          "netAmount": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "description": "Valor líquido ao fornecedor, ou null enquanto não foi calculado."
          },
          "payer": {
            "type": "object",
            "properties": {
              "cnpj": {
                "type": "string",
                "description": "CNPJ da construtora."
              },
              "name": {
                "type": "string",
                "description": "Razão social da construtora."
              }
            },
            "required": [
              "cnpj",
              "name"
            ],
            "additionalProperties": false,
            "description": "A construtora (tomadora) da operação."
          },
          "supplier": {
            "type": "object",
            "properties": {
              "cnpj": {
                "type": "string",
                "description": "CNPJ do fornecedor."
              },
              "name": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Nome do fornecedor, ou null."
              }
            },
            "required": [
              "cnpj",
              "name"
            ],
            "additionalProperties": false,
            "description": "O fornecedor da operação."
          },
          "externalReference": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "O identificador do seu ERP, ou null."
          },
          "reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Motivo de encerramento, quando houver — por exemplo Cancelada via integração ou Pré-autorização expirada. Senão null."
          },
          "stage": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Etapa em que a operação foi encerrada: PRE_AUTH, REQUEST ou SYSTEM. Senão null."
          },
          "extension": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991,
                "description": "Identificador da prorrogação."
              },
              "newDueDate": {
                "type": "string",
                "description": "Novo vencimento do boleto."
              },
              "totalAmount": {
                "type": "number",
                "description": "Valor total do boleto prorrogado."
              }
            },
            "required": [
              "id",
              "newDueDate",
              "totalAmount"
            ],
            "additionalProperties": false,
            "description": "Só nos eventos anticipation.extension_*: a prorrogação do boleto."
          }
        },
        "required": [
          "anticipationId",
          "status",
          "origin",
          "invoice",
          "netAmount",
          "payer",
          "supplier",
          "externalReference"
        ],
        "additionalProperties": false
      },
      "Errors": {
        "type": "object",
        "required": [
          "errors"
        ],
        "properties": {
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "code",
                "message"
              ],
              "properties": {
                "code": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          },
          "details": {
            "type": "array",
            "description": "Dado estruturado do erro, quando houver. No 409 PRE_AUTH_DUPLICATE_INVOICE: [{ \"anticipationId\": <id> }].",
            "items": {
              "type": "object"
            }
          }
        }
      }
    }
  }
}
