{
  "openapi": "3.0.3",
  "info": {
    "title": "mxMED — API de Integrações",
    "version": "1.0.0",
    "description": "Integração por clínica, empresa e ambiente. Catálogo e checkout existentes; sem acesso a prontuários, pacientes ou cartões. Documentação: https://mxmed.com.br/desenvolvedores. Sandbox com dados fictícios. A clínica fornece credenciais, autoriza produção e administra os limites. Condições entre a clínica e a empresa integradora são definidas diretamente entre elas."
  },
  "servers": [
    {
      "url": "https://api-v2.mxmed.com.br/api/integrations/v1"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "paths": {
    "/{environment}/catalog/{kind}": {
      "get": {
        "operationId": "get_catalog__kind_",
        "summary": "Consultar catálogo autorizado",
        "description": "Permissão: catalog:read. Limites por integração, clínica e plataforma. Consulte /desenvolvedores.",
        "parameters": [
          {
            "in": "path",
            "name": "environment",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "live"
              ]
            },
            "description": "Teste usa somente dados fictícios. A chave pertence a um único ambiente."
          },
          {
            "in": "path",
            "name": "kind",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "units",
                "doctors",
                "procedures"
              ]
            }
          },
          {
            "in": "query",
            "name": "after",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            },
            "required": false,
            "description": ""
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 50
            },
            "required": false,
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Operação concluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "items",
                        "nextCursor"
                      ],
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/CatalogItem"
                          }
                        },
                        "nextCursor": {
                          "type": "string",
                          "nullable": true,
                          "description": "Enviar em after. Nulo encerra a paginação."
                        }
                      }
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Sem permissão",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado nesta integração",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflito de estado ou idempotência",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tráfego, concorrência ou franquia",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporariamente indisponível",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/{environment}/availability": {
      "get": {
        "operationId": "get_availability",
        "summary": "Consultar horários publicados",
        "description": "Permissão: availability:read. Limites por integração, clínica e plataforma. Consulte /desenvolvedores.",
        "parameters": [
          {
            "in": "path",
            "name": "environment",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "live"
              ]
            },
            "description": "Teste usa somente dados fictícios. A chave pertence a um único ambiente."
          },
          {
            "in": "query",
            "name": "unitId",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            },
            "required": true,
            "description": ""
          },
          {
            "in": "query",
            "name": "doctorId",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            },
            "required": true,
            "description": ""
          },
          {
            "in": "query",
            "name": "date",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "required": true,
            "description": ""
          },
          {
            "in": "query",
            "name": "after",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            },
            "required": false,
            "description": ""
          }
        ],
        "responses": {
          "200": {
            "description": "Operação concluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "items",
                        "nextCursor"
                      ],
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Slot"
                          }
                        },
                        "nextCursor": {
                          "type": "string",
                          "nullable": true,
                          "description": "Enviar em after. Nulo encerra a paginação."
                        }
                      }
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Sem permissão",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado nesta integração",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflito de estado ou idempotência",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tráfego, concorrência ou franquia",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporariamente indisponível",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/{environment}/orders": {
      "post": {
        "operationId": "post_orders",
        "summary": "Criar link de compra, sem reservar ou cobrar",
        "description": "Permissão: orders:write. Limites por integração, clínica e plataforma. Consulte /desenvolvedores.",
        "parameters": [
          {
            "in": "path",
            "name": "environment",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "live"
              ]
            },
            "description": "Teste usa somente dados fictícios. A chave pertence a um único ambiente."
          },
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,100}$"
            },
            "description": "Repita a mesma chave e conteúdo em caso de timeout."
          }
        ],
        "responses": {
          "200": {
            "description": "Repetição idêntica, sem nova cobrança de consumo.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Operação concluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Sem permissão",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado nesta integração",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflito de estado ou idempotência",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tráfego, concorrência ou franquia",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporariamente indisponível",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewOrder"
              }
            }
          }
        }
      }
    },
    "/{environment}/orders/{id}": {
      "get": {
        "operationId": "get_orders__id_",
        "summary": "Acompanhar pedido da própria integração",
        "description": "Permissão: orders:read. Limites por integração, clínica e plataforma. Consulte /desenvolvedores.",
        "parameters": [
          {
            "in": "path",
            "name": "environment",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "live"
              ]
            },
            "description": "Teste usa somente dados fictícios. A chave pertence a um único ambiente."
          },
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operação concluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Sem permissão",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado nesta integração",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflito de estado ou idempotência",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tráfego, concorrência ou franquia",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporariamente indisponível",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/{environment}/orders/{id}/cancel": {
      "post": {
        "operationId": "post_orders__id__cancel",
        "summary": "Cancelar antes de iniciar o checkout",
        "description": "Permissão: orders:write. Limites por integração, clínica e plataforma. Consulte /desenvolvedores.",
        "parameters": [
          {
            "in": "path",
            "name": "environment",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "live"
              ]
            },
            "description": "Teste usa somente dados fictícios. A chave pertence a um único ambiente."
          },
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operação concluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Sem permissão",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado nesta integração",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflito de estado ou idempotência",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tráfego, concorrência ou franquia",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporariamente indisponível",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/{environment}/orders/{id}/simulate": {
      "post": {
        "operationId": "post_orders__id__simulate",
        "summary": "Simular pagamento em test, sem gateway",
        "description": "Permissão: orders:write. Limites por integração, clínica e plataforma. Consulte /desenvolvedores.",
        "parameters": [
          {
            "in": "path",
            "name": "environment",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "live"
              ]
            },
            "description": "Teste usa somente dados fictícios. A chave pertence a um único ambiente."
          },
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operação concluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Sem permissão",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado nesta integração",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflito de estado ou idempotência",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tráfego, concorrência ou franquia",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporariamente indisponível",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "scenario"
                ],
                "properties": {
                  "scenario": {
                    "type": "string",
                    "enum": [
                      "paid",
                      "declined",
                      "pending",
                      "expired"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "/{environment}/usage": {
      "get": {
        "operationId": "get_usage",
        "summary": "Consultar consumo sem cobrança",
        "description": "Permissão: qualquer chave válida. Limites por integração, clínica e plataforma. Consulte /desenvolvedores.",
        "parameters": [
          {
            "in": "path",
            "name": "environment",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "live"
              ]
            },
            "description": "Teste usa somente dados fictícios. A chave pertence a um único ambiente."
          }
        ],
        "responses": {
          "200": {
            "description": "Operação concluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Usage"
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Sem permissão",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado nesta integração",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflito de estado ou idempotência",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tráfego, concorrência ou franquia",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporariamente indisponível",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/{environment}/events": {
      "get": {
        "operationId": "get_events",
        "summary": "Recuperar até 50 eventos sem cobrança",
        "description": "Permissão: orders:read. Limites por integração, clínica e plataforma. Consulte /desenvolvedores.",
        "parameters": [
          {
            "in": "path",
            "name": "environment",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "live"
              ]
            },
            "description": "Teste usa somente dados fictícios. A chave pertence a um único ambiente."
          },
          {
            "in": "query",
            "name": "after",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            },
            "required": false,
            "description": "Use o último ID retornado até obter uma página vazia."
          }
        ],
        "responses": {
          "200": {
            "description": "Operação concluída.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "requestId"
                  ],
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "items": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Event"
                          }
                        }
                      }
                    },
                    "requestId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Chave inválida",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Sem permissão",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Não encontrado nesta integração",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflito de estado ou idempotência",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Limite de tráfego, concorrência ou franquia",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Temporariamente indisponível",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Em 429/503: segundos de espera quando informado."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "requestId"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Código estável"
              },
              "message": {
                "type": "string",
                "description": "Explicação em português"
              }
            }
          },
          "requestId": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "Order": {
        "type": "object",
        "required": [
          "id",
          "externalReference",
          "status",
          "amount",
          "expiresAt",
          "checkoutUrl",
          "environment"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "externalReference": {
            "type": "string",
            "description": "Referência da empresa, sem dados pessoais"
          },
          "status": {
            "type": "string",
            "description": "Situação do pedido",
            "enum": [
              "ABERTO",
              "PROCESSANDO",
              "PAGAMENTO_PENDENTE",
              "CONFIRMADO",
              "RECUSADO",
              "CANCELADO",
              "EXPIRADO",
              "CONCILIAR_COM_CLINICA",
              "DEVOLVIDO",
              "DEVOLVIDO_PARCIAL"
            ]
          },
          "amount": {
            "type": "number",
            "format": "double",
            "description": "Valor em reais definido pela clínica"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "checkoutUrl": {
            "type": "string",
            "format": "uri",
            "nullable": true,
            "description": "Nulo em teste ou após encerramento/início do checkout."
          },
          "environment": {
            "type": "string",
            "enum": [
              "test",
              "live"
            ]
          }
        }
      },
      "NewOrder": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "externalReference",
          "slotId",
          "unitId",
          "doctorId",
          "date",
          "procedureCode"
        ],
        "properties": {
          "externalReference": {
            "type": "string",
            "description": "Única por integração e ambiente. Não use CPF, nome ou e-mail.",
            "pattern": "^[A-Za-z0-9._:-]{1,100}$"
          },
          "slotId": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "unitId": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "doctorId": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "date": {
            "type": "string",
            "format": "date",
            "description": "Hoje até 30 dias à frente, calendário de São Paulo."
          },
          "procedureCode": {
            "type": "string",
            "description": "Código retornado pelo catálogo, preservando zeros iniciais.",
            "pattern": "^[0-9]{1,30}$"
          }
        }
      },
      "Slot": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "startAt": {
            "type": "string",
            "description": "Data e hora locais da clínica; sem conversão para UTC."
          },
          "unitId": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "doctorId": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "procedureCodes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "minimumAge": {
            "type": "integer"
          },
          "maximumAge": {
            "type": "integer"
          }
        }
      },
      "CatalogItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "description": "Apenas procedimentos"
          },
          "specialty": {
            "type": "string",
            "description": "Apenas profissionais"
          },
          "street": {
            "type": "string",
            "nullable": true
          },
          "number": {
            "type": "string",
            "nullable": true
          },
          "neighborhood": {
            "type": "string",
            "nullable": true
          },
          "city": {
            "type": "string",
            "nullable": true
          },
          "state": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "integrationId": {
            "type": "string",
            "format": "uuid"
          },
          "company": {
            "type": "string"
          },
          "environment": {
            "type": "string"
          },
          "permissions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "usage": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "month": {
                  "type": "string",
                  "description": "Primeiro dia da competência em São Paulo, serializado como data/hora sem fuso."
                },
                "calls": {
                  "type": "integer"
                },
                "processing": {
                  "type": "integer"
                },
                "allowance": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "Event": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "orderId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string"
          },
          "occurredAt": {
            "type": "string",
            "description": "Data/hora UTC."
          }
        }
      }
    }
  }
}
