{
  "info": {
    "name": "mxMED Integrações — sandbox",
    "description": "Preencha apiKey com a chave mx_test_ entregue pela clínica. Executa somente /test com dados fictícios. Sem pagamento real. Não inclua segredos ao compartilhar esta coleção. Para produção consulte a documentação e adapte em uma cópia.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api-v2.mxmed.com.br/api/integrations/v1"
    },
    {
      "key": "apiKey",
      "value": ""
    },
    {
      "key": "orderId",
      "value": ""
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "if(!pm.variables.get('apiKey')?.startsWith('mx_test_'))throw new Error('Use uma chave mx_test_ de sandbox.');",
          "if(!pm.collectionVariables.get('scenarioRef'))pm.collectionVariables.set('scenarioRef','demo-'+Date.now());",
          "const date=new Date(Date.now()+86400000-3*3600000).toISOString().slice(0,10);pm.variables.set('slotDate',date);"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "1. Unidades",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/test/catalog/units"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});"
            ]
          }
        }
      ]
    },
    {
      "name": "2. Profissionais",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/test/catalog/doctors"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});"
            ]
          }
        }
      ]
    },
    {
      "name": "3. Procedimentos",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/test/catalog/procedures"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});"
            ]
          }
        }
      ]
    },
    {
      "name": "4. Horários fictícios",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/test/availability?unitId=101&doctorId=201&date={{slotDate}}"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});"
            ]
          }
        }
      ]
    },
    {
      "name": "5. Criar pedido fictício",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{scenarioRef}}"
          }
        ],
        "url": "{{baseUrl}}/test/orders",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"externalReference\": \"{{scenarioRef}}\",\n  \"slotId\": 401,\n  \"unitId\": 101,\n  \"doctorId\": 201,\n  \"date\": \"{{slotDate}}\",\n  \"procedureCode\": \"10101012\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});",
              "if(pm.response.code<300)pm.collectionVariables.set('orderId',result.data.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "6. Simular pagamento fictício",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/test/orders/{{orderId}}/simulate",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"scenario\": \"paid\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});"
            ]
          }
        }
      ]
    },
    {
      "name": "7. Acompanhar pedido",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/test/orders/{{orderId}}"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});"
            ]
          }
        }
      ]
    },
    {
      "name": "8. Recuperar eventos",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/test/events?after=0"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});"
            ]
          }
        }
      ]
    },
    {
      "name": "9. Consultar consumo",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Api-Key",
            "value": "{{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/test/usage"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP de sucesso',()=>pm.expect(pm.response.code).to.be.within(200,299));",
              "const result=pm.response.json();pm.test('Resposta com requestId e data',()=>{pm.expect(result).to.have.property('requestId');pm.expect(result).to.have.property('data');});"
            ]
          }
        }
      ]
    }
  ]
}
