{
  "info": {
    "name": "Vainabag — API de Entregas (sandbox)",
    "description": "Fluxo completo de testes: token → webhook → entrega de teste → simulação. Preencha client_id e client_secret nas variáveis da coleção. O token é salvo sozinho pela requisição 1.\n\nDocumentação: https://api-pro.vainabag.com.br/integrations/v1/docs",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "base_url", "value": "https://api-pro.vainabag.com.br/integrations/v1" },
    { "key": "client_id", "value": "eak_..." },
    { "key": "client_secret", "value": "eas_..." },
    { "key": "token", "value": "" },
    { "key": "order_id", "value": "" },
    { "key": "webhook_id", "value": "" }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{token}}", "type": "string" }]
  },
  "item": [
    {
      "name": "1. Gerar token",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": ["const body = pm.response.json();", "if (body.access_token) pm.collectionVariables.set('token', body.access_token);"]
          }
        }
      ],
      "request": {
        "auth": { "type": "noauth" },
        "method": "POST",
        "header": [{ "key": "Content-Type", "value": "application/json" }],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"grant_type\": \"client_credentials\",\n  \"client_id\": \"{{client_id}}\",\n  \"client_secret\": \"{{client_secret}}\"\n}"
        },
        "url": "{{base_url}}/auth/token"
      }
    },
    {
      "name": "2. Cadastrar webhook",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": ["const body = pm.response.json();", "if (body.webhook) pm.collectionVariables.set('webhook_id', body.webhook.id);"]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [{ "key": "Content-Type", "value": "application/json" }],
        "body": { "mode": "raw", "raw": "{\n  \"url\": \"https://seu-sistema.com/webhooks/vainabag\",\n  \"label\": \"Testes\"\n}" },
        "url": "{{base_url}}/webhooks"
      }
    },
    {
      "name": "3. Testar webhook",
      "request": { "method": "POST", "header": [], "url": "{{base_url}}/webhooks/{{webhook_id}}/test" }
    },
    {
      "name": "4. Zonas atendidas",
      "request": { "method": "GET", "header": [], "url": "{{base_url}}/delivery-zones" }
    },
    {
      "name": "5. Criar entrega de teste",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": ["const body = pm.response.json();", "if (body.id) pm.collectionVariables.set('order_id', body.id);"]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" },
          { "key": "Idempotency-Key", "value": "{{$guid}}" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"clientName\": \"Maria Teste\",\n  \"clientPhone\": \"11999999999\",\n  \"address\": { \"street\": \"Rua Exemplo\", \"number\": \"100\", \"neighborhood\": \"Centro\" },\n  \"paymentMethod\": \"PIX\",\n  \"test\": true\n}"
        },
        "url": "{{base_url}}/orders"
      }
    },
    {
      "name": "6. Consultar entrega",
      "request": { "method": "GET", "header": [], "url": "{{base_url}}/orders/{{order_id}}" }
    },
    {
      "name": "Simular",
      "item": [
        { "name": "Pronta para coleta", "request": { "method": "POST", "header": [], "url": "{{base_url}}/orders/{{order_id}}/simulate/ready" } },
        { "name": "Entregador aceitou", "request": { "method": "POST", "header": [], "url": "{{base_url}}/orders/{{order_id}}/simulate/driver-accept" } },
        { "name": "Coletou (em rota)", "request": { "method": "POST", "header": [], "url": "{{base_url}}/orders/{{order_id}}/simulate/collect" } },
        { "name": "Entregue", "request": { "method": "POST", "header": [], "url": "{{base_url}}/orders/{{order_id}}/simulate/deliver" } },
        { "name": "Saldo insuficiente", "request": { "method": "POST", "header": [], "url": "{{base_url}}/orders/{{order_id}}/simulate/insufficient-balance" } },
        { "name": "Cancelar", "request": { "method": "POST", "header": [], "url": "{{base_url}}/orders/{{order_id}}/simulate/cancel" } }
      ]
    }
  ]
}
