{
  "openapi": "3.1.0",
  "info": {
    "title": "ZoryCash API",
    "version": "1.0.0",
    "description": "Infraestrutura de alta performance para pagamentos PIX, liquidação em USDT e automação financeira no Brasil. Rota Black: PIX entrada/saída R$ 2–1.000, cripto saída R$ 10–1.000 e cripto entrada R$ 10–3.000. O nível da conta pode reduzir, mas nunca ampliar, o teto da rota.",
    "contact": {
      "name": "Suporte Técnico ZoryCash",
      "email": "suporte@zorycash.com.br",
      "url": "https://app.zorycash.com.br/docs"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://app.zorycash.com.br/legal"
    }
  },
  "servers": [
    {
      "url": "https://api.zorycash.com.br/api/v1",
      "description": "Servidor de Produção"
    },
    {
      "url": "https://app.zorycash.com.br/api/v1",
      "description": "Gateway Secundário"
    }
  ],
  "security": [{ "apiKeyAuth": [] }, { "bearerAuth": [] }],
  "paths": {
    "/pix/charge": {
      "post": {
        "operationId": "createPixCharge",
        "summary": "Criar cobrança PIX imediata",
        "description": "Gera um QR Code estático ou dinâmico e código Pix Copia e Cola para pagamento instantâneo.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PixChargeRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cobrança gerada com sucesso",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PixChargeResponse" }
              }
            }
          },
          "202": {
            "description": "Cobrança aceita pelo provedor e aguardando reconciliação local",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PixChargeResponse" }
              }
            }
          },
          "400": {
            "description": "Payload inválido ou validação falhou",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "401": {
            "description": "Chave de API inválida ou não fornecida",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "403": {
            "description": "Conta não verificada, restrita para a operação ou suspensa",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "409": {
            "description": "external_ref reutilizada com valor diferente",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "422": {
            "description": "Valor fora do intervalo da rota ou do limite operacional atual da conta",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "429": {
            "description": "Limite adaptativo da conta excedido; respeite o cabeçalho Retry-After",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          }
        }
      }
    },
    "/pix/withdraw": {
      "post": {
        "operationId": "createPixWithdrawal",
        "summary": "Realizar transferência ou saque PIX (PIX Cashout)",
        "description": "Envia um pagamento PIX instantâneo para qualquer chave Pix de destino.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PixWithdrawRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transferência realizada ou agendada",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PixWithdrawResponse" }
              }
            }
          },
          "202": {
            "description": "Saque em processamento ou aguardando reconciliação após timeout",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PixWithdrawResponse" }
              }
            }
          },
          "400": {
            "description": "Chave PIX inválida ou parâmetros incorretos",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "401": {
            "description": "Chave de API não autorizada",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "402": {
            "description": "Saldo insuficiente para saque",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "403": {
            "description": "Conta não verificada ou suspensa",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "409": {
            "description": "external_ref reutilizada com valor ou destino PIX diferentes",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "422": {
            "description": "Destino recusado ou valor fora do intervalo operacional permitido",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          },
          "429": {
            "description": "Limite adaptativo da conta excedido; respeite o cabeçalho Retry-After",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          }
        }
      }
    },
    "/balance": {
      "get": {
        "operationId": "getBalance",
        "summary": "Consultar saldo da conta",
        "description": "Retorna saldo disponível e totais históricos em centavos (BRL).",
        "responses": {
          "200": {
            "description": "Saldo consultado com sucesso",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BalanceResponse" }
              }
            }
          },
          "401": {
            "description": "Não autorizado",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          }
        }
      }
    },
    "/transactions": {
      "get": {
        "operationId": "listTransactions",
        "summary": "Listar transações",
        "description": "Lista o histórico de cobranças pertencentes à chave autenticada.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 50 },
            "description": "Quantidade máxima de registros"
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de transações retornada com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/Transaction" }
                }
              }
            }
          },
          "401": {
            "description": "Não autorizado",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          }
        }
      }
    },
    "/transactions/{id}": {
      "get": {
        "operationId": "getTransactionById",
        "summary": "Consultar transação por ID",
        "description": "Retorna os detalhes completos de uma cobrança ou saque pelo ID ou external_ref.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "ID da transação na ZoryCash"
          }
        ],
        "responses": {
          "200": {
            "description": "Transação encontrada",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Transaction" }
              }
            }
          },
          "404": {
            "description": "Transação não encontrada",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } }
            }
          }
        }
      }
    },
    "/splits": {
      "get": {
        "operationId": "listSplits",
        "summary": "Listar regras de divisão de pagamentos (Split)",
        "description": "Retorna as regras ativas de comissionamento e repasse automático entre parceiros.",
        "responses": {
          "200": {
            "description": "Regras de split ativas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "splits": { "type": "array", "items": { "type": "object" } } }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Chave privada da API ZoryCash (ex: ak_live_...)"
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "Alternativamente, passe Authorization: Bearer <ak_live_...>"
      }
    },
    "schemas": {
      "PixChargeRequest": {
        "type": "object",
        "required": ["amount_cents"],
        "properties": {
          "amount_cents": {
            "type": "integer",
            "minimum": 500,
            "maximum": 10000000,
            "description": "Valor em centavos (ex: 5000 = R$ 50,00)",
            "example": 5000
          },
          "external_ref": {
            "type": "string",
            "description": "Identificador único do pedido no seu sistema",
            "example": "PEDIDO-1002"
          },
          "description": { "type": "string", "example": "Pagamento do pedido PEDIDO-1002" },
          "payer_name": { "type": "string", "example": "João da Silva" },
          "payer_doc": {
            "type": "string",
            "description": "CPF ou CNPJ (apenas dígitos)",
            "example": "12345678909"
          },
          "payer_email": {
            "type": "string",
            "format": "email",
            "maxLength": 255,
            "description": "E-mail do pagador",
            "example": "cliente@exemplo.com"
          }
        }
      },
      "PixChargeResponse": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "tx_9f8a8123" },
          "status": {
            "type": "string",
            "enum": ["pending", "processing", "paid"],
            "example": "pending"
          },
          "amount_cents": { "type": "integer", "example": 5000 },
          "pix": {
            "type": "object",
            "properties": {
              "copy_paste": { "type": "string", "example": "00020126580014BR.GOV.BCB.PIX0136..." },
              "qr_code_image": { "type": "string", "description": "QR Code em data URI" },
              "expires_at": { "type": "string", "format": "date-time" }
            }
          },
          "created_at": { "type": "string", "format": "date-time" },
          "warning": {
            "type": "string",
            "enum": ["local_update_pending"],
            "description": "Presente apenas quando a operação exige reconciliação local"
          }
        }
      },
      "PixWithdrawRequest": {
        "type": "object",
        "required": ["amount_cents", "pix_key", "pix_key_type"],
        "properties": {
          "amount_cents": {
            "type": "integer",
            "minimum": 500,
            "maximum": 10000000,
            "description": "Valor em centavos",
            "example": 2500
          },
          "pix_key": { "type": "string", "example": "financeiro@empresa.com" },
          "pix_key_type": {
            "type": "string",
            "enum": ["cpf", "cnpj", "email", "phone", "random"],
            "example": "email"
          },
          "external_ref": { "type": "string", "example": "SAQUE-0091" }
        }
      },
      "PixWithdrawResponse": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "wdr_1298ab" },
          "status": {
            "type": "string",
            "enum": ["processing", "completed", "failed"],
            "example": "processing"
          },
          "amount_cents": { "type": "integer", "example": 2500 },
          "fee_cents": { "type": "integer", "example": 150 },
          "warning": {
            "type": "string",
            "enum": ["local_update_pending", "com_timeout"]
          }
        }
      },
      "BalanceResponse": {
        "type": "object",
        "properties": {
          "available_cents": {
            "type": "integer",
            "description": "Saldo disponível em centavos",
            "example": 154000
          },
          "total_received_cents": {
            "type": "integer",
            "description": "Total histórico recebido em centavos",
            "example": 500000
          },
          "total_withdrawn_cents": {
            "type": "integer",
            "description": "Total histórico sacado em centavos",
            "example": 346000
          }
        }
      },
      "Transaction": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "tx_9f8a8123" },
          "amount_cents": { "type": "integer", "example": 5000 },
          "net_cents": { "type": "integer", "example": 4900 },
          "status": { "type": "string", "example": "paid" },
          "payment_method": { "type": "string", "example": "pix" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": { "type": "string", "example": "unauthorized" },
              "message": { "type": "string", "example": "Chave de API inválida ou ausente." },
              "hint": {
                "type": "string",
                "example": "Gere uma chave privada no painel ZoryCash em https://app.zorycash.com.br/api-keys"
              }
            }
          }
        }
      }
    }
  }
}
